iptables不單隻防火牆這麼簡單,NAT轉發這些都很強大。可是市面上iptables的教程基本都是圍繞着CentOS 6來展開的,而對於CentOS 7和Ubuntu又不同的寫法,尤爲是Ubuntu竟然加了一個ufw作爲封裝,目的是爲了簡化iptables,我的感受比較亂,封裝了太多致使上層看不到更多的原理!而CentOS 7整理來講會保持,可是有些規則仍是變了,使用的是firewalld的新概念。html
下面實現的是經過一個內網IP重定向到一個外網IP上,或者訪問一個外網IP重定向到一個內網IP,基本操做保持一致,主要目的就是重定向,有點相似host:linux
一、經過代理訪問121.8.210.236的轉向訪問192.168.191.236ubuntu
sudo iptables -t nat -A OUTPUT -d 121.8.210.236 -j DNAT --to-destination 192.168.191.236
sudo iptables -t nat -A OUTPUT -d 10.0.0.2 -p tcp --dport 11211 -j DNAT --to-destination 192.168.1.33:11211
二、反過來,訪問192.168.191.236的轉向訪問121.8.210.236tcp
sudo iptables -t nat -A OUTPUT -d 192.168.191.236 -j DNAT --to-destination 121.8.210.236
參考:ui
http://blog.chinaunix.net/uid-7411781-id-3239324.html(以上內容參考此篇文章)spa
如下是iptables作NAT轉發的一些教程:.net
https://www.xindelinux.top/257.html代理
http://www.360doc.com/content/15/0629/14/8737500_481468012.shtmlunix
http://www.itnose.net/detail/6645457.html
http://www.linuxidc.com/Linux/2013-08/88983.htm
http://www.cnblogs.com/zejin2008/p/5917654.html
http://blog.chinaunix.net/uid-22780578-id-3346350.html
http://www.cnblogs.com/general0878/p/5757377.html
http://www.linuxidc.com/Linux/2017-02/140556.htm
https://community.rackspace.com/products/f/25/t/4504
https://www.cyberciti.biz/faq/ubuntu-start-stop-iptables-service/