linux IP地址重定向
linux IP地址重定向
主要是实现通过一个内网IP重定向到外网IP上,或者访问一个外网IP重定向到内网Ip上。基本操作保持一致,主要目的就是重定向。
1 开启Linux路由转发功能
修改/etc/sysctl.conf配置文件。将net.ipv4.ip_forward参数值设置为1。然后执行 sysctl -p 使配置生效。
2 相关命令
查看路由
iptables -t nat -L -nv
重定向本机出站TCP/UDP数据包。
//将本机发往172.23.17.154和172.23.17.153的UDP数据包分别重定向到59.195.2.27和59.195.2.26 iptables -t nat -A OUTPUT -p udp -d 172.23.17.154 -j DNAT --to-destination 59.195.2.27 iptables -t nat -A OUTPUT -p udp -d 172.23.17.153 -j DNAT --to-destination 59.195.2.26 //将本机发往172.23.17.154和172.23.17.153的TCP数据包分别重定向到59.195.2.27和59.195.2.26 iptables -t nat -A OUTPUT -p tcp -d 172.23.17.154 -j DNAT --to-destination 59.195.2.27 iptables -t nat -A OUTPUT -p tcp -d 172.23.17.153 -j DNAT --to-destination 59.195.2.26
重定向本机转发TCP/UDP数据包。
//将本机转发至172.23.17.154和172.23.17.153的UDP数据包分别重定向到59.195.2.27和59.195.2.26 iptables -t nat -A PREROUTING -p udp -d 172.23.17.154 -j DNAT --to-destination 59.195.2.27 iptables -t nat -A PREROUTING -p udp -d 172.23.17.153 -j DNAT --to-destination 59.195.2.26 //将本机转发至1172.23.17.154和172.23.17.153的TCP数据包分别重定向到59.195.2.27和59.195.2.26 iptables -t nat -A PREROUTING -p tcp -d 172.23.17.154 -j DNAT --to-destination 59.195.2.27 iptables -t nat -A PREROUTING -p tcp -d 172.23.17.153 -j DNAT --to-destination 59.195.2.26
浙公网安备 33010602011771号