使用iptables做4层端口转发
目录
用途:有两台机器,需要用其中的一台机器做跳板,转发另一台机器一个特定的端口,机器列表如下
机器 | IP |
---|---|
iptables机器 | 10.0.0.41 |
web服务器 | 10.0.0.42:8000 |
开启内核转发功能
转发请求到目标主机
iptables -t nat -A PREROUTING -4 -p tcp -d 10.0.0.41 --dport 80 -j DNAT --to-destination 10.0.0.42:8000
转发数据包回路
iptables -t nat -A POSTROUTING -4 -p tcp -d 10.0.0.42 --dport 8000 -j MASQUERADE
其他操作
查看nat表
sudo iptables -t nat -L
清空nat表配置
sudo iptables -t nat -F
查看filter表
sudo iptables -L
清空filter表
sudo iptables -F