将流入服务器的公网IP的80端口的流量全部转发到另一个公网IP(1.2.3.4)的80端口上。

操作

iptables -P FORWARD ACCEPT
iptables -t nat -A PREROUTING -p tcp -m state --state NEW -m tcp --dport 80 -j DNAT --to-destination 1.2.3.4:80
iptables -t nat -A POSTROUTING -j MASQUERADE

开启服务器路由转发功能(不需要重启服务器)

echo 1 > /proc/sys/net/ipv4/ip_forward

永久开启服务器路由转发功能

sed -i '/^net.ipv4.ip_forward\b/s/0/1/' /etc/sysctl.conf

 

相关文章:

  • 2021-11-25
  • 2021-06-02
  • 2021-09-27
  • 2022-12-23
猜你喜欢
  • 2021-05-11
  • 2021-06-16
  • 2021-10-02
  • 2022-01-07
  • 2021-06-15
相关资源
相似解决方案