Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common methods of port forwarding under Linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what are the common methods of port forwarding under Linux". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what are the common methods of port forwarding under Linux".

Port forwarding service is a policy defined by a set of port forwarding rules. A port forwarding service can be applied to one or more virtual machines. Then the inbound network access of the virtual machine is managed according to the policy defined by the port forwarding service.

01. SSH port forwarding

SSH provides a very interesting function, which is port forwarding, which can forward the network data of other TCP ports through SSH links, and automatically provides corresponding encryption and decryption services.

(1) Local port forwarding

Ssh-fgN-L 2222:localhost:22 localhost (2) remote Port Forwardin

Ssh-fgN-R 2222:host1:22 localhost (3) dynamic forwarding

Ssh-fgN-D 12345 root@host12, iptables port forwarding

Iptables is used below CentOS 7.0, and packets can be forwarded through iptables.

(1) enable data forwarding function

Vi / etc/sysctl.conf # add a line of net.ipv4.ip_forward=1// to enable data forwarding sysctl-p (2) forward the local port to the local port

Iptables-t nat-A PREROUTING-p tcp-- dport 2222-j REDIRECT-- to-port 22 (3) forwards the port of this machine to another machine

Iptables-t nat-A PREROUTING-d 192.168.172.130-p tcp-- dport 8000-j DNAT-- to-destination 192.168.172.131:80iptables-t nat-A POSTROUTING-d 192.168.172.131-p tcp-- dport 80-j SNAT-- to 192.168.172.13 clear all chains of nat table iptables-t nat-F PREROUTING03, firewall port forwarding

CentOS 7.0 and above uses firewall, and port forwarding is implemented through command line configuration.

(1) enable camouflage IP

Firewall-cmd-- permanent-- add-masquerade (2) configures port forwarding to forward access to port 12345 on this machine to port 22 on another server.

Firewall-cmd-- permanent-- add-forward-port=port=12345:proto=tcp:toaddr=192.168.172.131:toport=22 (3) is reloaded to invalidate it.

Firewall-cmd-reload04, rinetd port forwarding

Rinetd is a lightweight TCP forwarding tool that enables port mapping / forwarding / redirection with simple configuration.

(1) download source code

Wget https://li.nux.ro/download/nux/misc/el7/x86_64/rinetd-0.62-9.el7.nux.x86_64.rpm (2) install rinetd

Rpm-ivh rinetd-0.62-9.el7.nux.x86_64.rpm (3) Edit configuration file

Vi rinetd.conf 0.0.0.0 1234 127.0.0.1 22 (4) initiates forwarding

Rinetd-c / etc/rinetd.conf05, ncat port forwarding

Netcat (abbreviated as nc) is known as the "Swiss Army knife" in the field of network security, a simple and useful tool. This paper introduces a method of port forwarding using netcat.

(1) install ncat

Yum install nmap-ncat-y (2) listens on native port 9876 and forwards data to port 80 of 192.168.172.131

Ncat-sh-exec "ncat 192.168.172.13180"-l 9876-keep-open06, socat port forwarding

Socat is a multi-functional network tool that uses socat for port forwarding.

(1) socat installation

Yum install-y socat (2) listens locally on port 12345 and forwards the request to port 22 of 192.168.172.131.

Socat TCP4-LISTEN:12345,reuseaddr,fork TCP4:192.168.172.131:2207, portmap port forwarding

Linux version of lcx, private network port forwarding tool.

(1) download address:

Http://www.vuln.cn/wp-content/uploads/2016/06/lcx_vuln.cn_.zip (2) listens on local port 1234 and forwards it to port 22 of 192.168.172.131

. / portmap-M1-p1 1234-h3 192.168.172.131-p222 are all the contents of this article entitled "what are the common methods of port forwarding under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report