CentOS 6/7 开启端口转发的代码
以下代码以本机81端口转发到本机80端口为例
CentOS 6 使用iptables实现:
echo net.ipv4.ip_forward=1>>/etc/sysctl.conf sysctl -p iptables -A INPUT -m tcp -p tcp --dport 81 -j ACCEPT iptables -t nat -A PREROUTING -p tcp --dport 81 -j REDIRECT --to-ports 80 service iptables save service iptables restart
CentOS 7 使用firewalld实现:
echo net.ipv4.ip_forward=1>>/etc/sysctl.conf sysctl -p firewall-cmd --zone=public --add-port=81/tcp --permanent firewall-cmd --add-masquerade --permanent firewall-cmd --add-forward-port=port=81:proto=tcp:toport=80 --permanent firewall-cmd --reload
使用端口转发之后,就可以配合免备案CDN实现相应的(具体不明说了)
请自行测试,如有问题请联系 www.oocolo.com