凡是处事器会有许多块网卡,,因此也可能会连接到差此外网络,在断绝的网络中,某些处事可能会需要进行通信,此时处事器颠末配置就可以承当起了转发数据包的成果。
一、Windows Server 下实现端口映射
1. 盘问端口映射情况
netsh interface portproxy show v4tov4
2. 盘问某一个IP的所有端口映射情况
netsh interface portproxy show v4tov4 | find "[方针IP]"
例:netsh interface portproxy show v4tov4 | find "192.168.1.1"
3. 增加一个端口映射
netsh interface portproxy add v4tov4 listenaddress=[外网IP] listenport=[外网端口] connectaddress=[内网IP] connectport=[内网端口]
例:netsh interface portproxy add v4tov4 listenaddress=2.2.2.2 listenport=8080 connectaddress=192.168.1.50 connectport=80
4. 删除一个端口映射
netsh interface portproxy delete v4tov4 listenaddress=[外网IP] listenport=[外网端口]
例:netsh interface portproxy delete v4tov4 listenaddress=2.2.2.2 listenport=8080
二、Linux 下实现端口映射
1. 允许数据包转发:
echo 1 >/proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -j MASQUERADE
2. 设置端口转发:
iptables -t nat -A PREROUTING -p tcp -m tcp --dport [外网端口] -j DNAT --to-destination [内网地点]:[内网端口]
例如: iptables -t nat -A PREROUTING -p tcp -m tcp --dport 6080 -j DNAT --to-destination 10.0.0.100:6090
3. 生存配置。如果不生存,重启后此映射将掉效
service iptables save
Linux或Windows上实现端口映射