維基地址
https://en.wikipedia.org/wiki/Iptables
定義
IPv4協(xié)議下,linux的防火墻服務(wù)腹忽,可用于ip訪(fǎng)問(wèn)控制来累,端口轉(zhuǎn)發(fā)等。
安裝(centOS)
systemctl disable firewalld
yum remove firewalld -y
yum install iptables-services -y
systemctl enable iptables
常用功能
1窘奏,查看當(dāng)前iptables規(guī)則
iptables -L -n
2嘹锁,清除現(xiàn)有規(guī)則
清除預(yù)設(shè)表filter中的所有規(guī)則鏈的規(guī)則
iptables -F?
清除預(yù)設(shè)表filter中使用者自定鏈中的規(guī)則
iptables -X
規(guī)則生效
service iptables save
service iptables restart
3,設(shè)定iptables規(guī)則
暫無(wú)
4着裹,查看NAT(Network Address Translation)規(guī)則
iptables -t nat -L
5领猾,設(shè)定映射規(guī)則
18081端口請(qǐng)求轉(zhuǎn)發(fā)到18080端口
iptables -t nat -A PREROUTING -p tcp --dport 18081 -j REDIRECT --to-port 18080
iptables -t nat -A OUTPUT -o lo -p tcp --dport18081-j REDIRECT --to-port18080
規(guī)則生效
service iptables save
service iptables restart
tips:
/etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p
要實(shí)現(xiàn)不同ip地址間的轉(zhuǎn)發(fā),需要修改net.ipv4.ip_forward為1骇扇,默認(rèn)為0摔竿,即關(guān)閉。