Ubuntu iptables 內(nèi)網(wǎng)端口映射
使用Ubuntu iptables 有許多地方能進(jìn)行運(yùn)作,比如:內(nèi)網(wǎng)端口映射
1.系統(tǒng)環(huán)境
內(nèi)網(wǎng)兩臺(tái)服務(wù)器:
A 172.16.119.128
B 172.16.119.129
希望將A機(jī)器的80端口映射到B機(jī)器的8013端口。
2.設(shè)置步驟
2.1./etc/sysctl.conf配置文件修改
刪除“# net.ipv4.ip_forward = 1”行前面的“#”。 默認(rèn)該行被注釋掉的。
2.2.查看現(xiàn)有配置信息
iptables -L
如果顯示內(nèi)容如下:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
表示無(wú)任何設(shè)置,可以繼續(xù)下一步操作。
否則執(zhí)行:
iptalbes -F
iptalbes -X
iptalbes -Z
2.3.設(shè)置端口映射
分別執(zhí)行:
iptables -t nat -A PREROUTING -d 172.16.119.128 -p tcp --dport 80 -j DNAT --to-destination 172.16.119.129:8013
iptables -t nat -A POSTROUTING -d 172.16.119.129 -p tcp --dport 8013 -j SNAT --to 172.16.119.128
iptables -A FORWARD -o eth0 -d 172.16.119.129 -p tcp --dport 8013 -j ACCEPT
iptables -A FORWARD -i eth0 -s 172.16.119.129 -p tcp --sport 8013 -j ACCEPT
2.4.驗(yàn)證端口映射
此時(shí),訪(fǎng)問(wèn)http://172.16.119.128/abc.htm,應(yīng)該能訪(fǎng)問(wèn)到對(duì)應(yīng)129服務(wù)器上端口為8013網(wǎng)站的abc.htm頁(yè)面。
3.設(shè)置開(kāi)機(jī)自動(dòng)加載iptables的配置文件
3.1 保存配置
執(zhí)行命令:
# iptables-save > /etc/init.d/iptables.up.rules
將當(dāng)前配置保存再iptables.up.rules文件中,文件名可以自己決定。
3.2 修改網(wǎng)卡配置文件
在網(wǎng)卡IP配置文件/etc/network/interfaces末行加入(/etc/init.d/iptables.up.rules可改成自己定義的配置文件位置和名稱(chēng))
pre-up iptables-restore < /etc/init.d/iptables.up.rules
3.3 重啟服務(wù)器驗(yàn)證
shutdown -r now
通過(guò)是正文的三大步介紹,我們清楚的知道了Ubuntu iptables 內(nèi)網(wǎng)端口映射的組建情況!希望對(duì)你們有用!
【編輯推薦】
- 如何使用 ubuntu iptables 防止IP攻擊
- ubuntu防火墻iptables使用指南
- iptables常用命令
- RedHat7.2下使用IPTABLES實(shí)現(xiàn)IP轉(zhuǎn)發(fā)
- 紅旗Linux上的iptables使用簡(jiǎn)介
- iptables-restore中文手冊(cè)