In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to configure port forwarding under CentOS, which has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article. Let's take a look at it.
Enable IP forwarding
First, enable the IP forwarding function, which is disabled by default.
Temporary modification:
# echo 1 > / proc/sys/net/ipv4/ip_forward
It takes effect immediately after the modification, but reverts to the default value of 0 if the system is rebooted.
Permanent modification:
Vi / etc/sysctl.conf
# find the following value and change 0 to 1
Net.ipv4.ip_forward = 1
# sysctl-p (make it effective immediately)
The default value of 0 is to disable ip forwarding. If you change it to 1, you can enable ip forwarding.
Configure port forwarding
Suppose that when a user accesses 172.16.4.247VR 728, I want it to be forwarded to 172.16.4.97VR 80:
# iptables-t nat-A PREROUTING-p tcp-d 113.108.110.61-- dport 728-j DNAT-- to-destination 172.16.4.97 tcp 80
# iptables-t nat-A POSTROUTING-p tcp-s 172.16.4.97-- sport 80-j SNAT-- to-source 172.16.4.247
# service iptables save (save the current rule to / etc/sysconfig/iptables)
Alternatively, you can modify the / etc/sysconfig/iptables file directly:
-A PREROUTING-d 172.16.4.247 tcp 32-p tcp-m DNAT-- dport 728-j DNAT-- to-destination 172.16.4.97 Vor80
-A POSTROUTING-s 172.16.4.97 tcp 32-p tcp-m tcp-- sport 80-j SNAT-- to-source 172.16.4.247
Finally, don't forget to open port 728.
-An INPUT-p tcp-m state-- state NEW-m tcp-- dport 728-j ACCEPT
After the configuration is complete, remember to restart the firewall:
# service iptables restart
Native port forwarding
If you only need to forward between different ports of this machine, it will be easier. For example, to access http://ip:729, I want to return the content of http://ip:80. The configuration is as follows:
[root@localhost sbin] # iptables-t nat-A PREROUTING-p tcp-- dport 729-j REDIRECT-- to-ports 80
[root@localhost sbin] # service iptables save
[root@localhost sbin] # service iptables restart
Thank you for reading this article carefully. I hope the article "how to configure Port forwarding under CentOS" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.