windows、linux做nat映射
公司需求要在内网的两台windows服务器做公网nat映射,并且定制端口,由于本人还是对linux熟悉点,就还是以一台linux服务器做转发完成。
参考网站:
http://www.cnblogs.com/JemBai/archive/2009/03/19/1416364.html
http://wqmsl.blog.51cto.com/847418/404283
http://www.chinaitlab.com/www/special/linux11.asp
参考网站:
http://www.cnblogs.com/JemBai/archive/2009/03/19/1416364.html
http://wqmsl.blog.51cto.com/847418/404283
http://www.chinaitlab.com/www/special/linux11.asp
环境如下:
1. 在局域网的客户机上配置路由指向,要对应到dnat服务器的网关。
2. 提供服务的机器上,默认路由要配置了dnat的网关
环境:client windows 2008 192.168.1.100 255.255.255.0
192.168.1.1
10.1.16.11
tomcat服务端口:8091
nat server linux 6.4 192.168.1.101 255.255.255.0
10.1.134.230 255.255.255.0
10.1.134.1
10.1.16.11
1.在windows环境命令如下:
查看路由表信息:route print
如果没有指向则删除原指向
#route delete 192.168.1.101
#route delete 0.0.0.0
添加新指向到ip地址为192.168.1.101。
#route add 0.0.0.0 mask 0.0.0.0 192.168.1.101
linux下:
# route add -host 10.20.30.148 gw 10.20.30.40 添加到网络的路由
# route add -net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
添加默认路由
# route add default gw 192.168.1.1
删除路由
# route del -host 192.168.1.2 dev eth0:0
# route del -host 10.20.30.148 gw 10.20.30.40
linux server主机配置:
将防火墙改为路由模式:
#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
#sysctl -p
或者
#echo "1" > /proc/sys/net/ipv4/ip_forward
将防火墙规则清空:
#iptables -F
#iptables -Z
#iptables -X
添加dnat映射:
#iptables -t nat -A PREROUTING -d 10.1.134.230 -p tcp --dport 8091 -j DNAT --to 192.168.1.100:8091
#iptalbes-restore < iptables.txt(将txt文本重载)
修改filer文件如下:(可见linux主机中的iptables.txt文件)
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*raw
:PREROUTING ACCEPT [32523:5305427]
:OUTPUT ACCEPT [129:17789]
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*mangle
:PREROUTING ACCEPT [32523:5305427]
:INPUT ACCEPT [8148:1355554]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [129:17789]
:POSTROUTING ACCEPT [129:17789]
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*nat
:PREROUTING ACCEPT [2122:416096]
:POSTROUTING ACCEPT [1:60]
:OUTPUT ACCEPT [1:60]
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 8091 -j DNAT --to-destination 192.168.1.100:8091
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.168.1.100:8080
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 1521 -j DNAT --to-destination 192.168.1.100:1521
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.168.1.103:8080
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*filter
:INPUT ACCEPT [973221:107128571]
:FORWARD ACCEPT [6717:5975620]
:OUTPUT ACCEPT [2876611:5736225559]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22:10000 -j ACCEPT
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
#service iptables save
#service iptables restart
1. 在局域网的客户机上配置路由指向,要对应到dnat服务器的网关。
2. 提供服务的机器上,默认路由要配置了dnat的网关
环境:client windows 2008 192.168.1.100 255.255.255.0
192.168.1.1
10.1.16.11
tomcat服务端口:8091
nat server linux 6.4 192.168.1.101 255.255.255.0
10.1.134.230 255.255.255.0
10.1.134.1
10.1.16.11
1.在windows环境命令如下:
查看路由表信息:route print
如果没有指向则删除原指向
#route delete 192.168.1.101
#route delete 0.0.0.0
添加新指向到ip地址为192.168.1.101。
#route add 0.0.0.0 mask 0.0.0.0 192.168.1.101
linux下:
# route add -host 10.20.30.148 gw 10.20.30.40 添加到网络的路由
# route add -net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
添加默认路由
# route add default gw 192.168.1.1
删除路由
# route del -host 192.168.1.2 dev eth0:0
# route del -host 10.20.30.148 gw 10.20.30.40
linux server主机配置:
将防火墙改为路由模式:
#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
#sysctl -p
或者
#echo "1" > /proc/sys/net/ipv4/ip_forward
将防火墙规则清空:
#iptables -F
#iptables -Z
#iptables -X
添加dnat映射:
#iptables -t nat -A PREROUTING -d 10.1.134.230 -p tcp --dport 8091 -j DNAT --to 192.168.1.100:8091
#iptalbes-restore < iptables.txt(将txt文本重载)
修改filer文件如下:(可见linux主机中的iptables.txt文件)
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*raw
:PREROUTING ACCEPT [32523:5305427]
:OUTPUT ACCEPT [129:17789]
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*mangle
:PREROUTING ACCEPT [32523:5305427]
:INPUT ACCEPT [8148:1355554]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [129:17789]
:POSTROUTING ACCEPT [129:17789]
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*nat
:PREROUTING ACCEPT [2122:416096]
:POSTROUTING ACCEPT [1:60]
:OUTPUT ACCEPT [1:60]
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 8091 -j DNAT --to-destination 192.168.1.100:8091
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.168.1.100:8080
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 1521 -j DNAT --to-destination 192.168.1.100:1521
-A PREROUTING -d 10.1.134.230/32 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.168.1.103:8080
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
# Generated by iptables-save v1.4.7 on Tue Apr 22 11:37:52 2014
*filter
:INPUT ACCEPT [973221:107128571]
:FORWARD ACCEPT [6717:5975620]
:OUTPUT ACCEPT [2876611:5736225559]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22:10000 -j ACCEPT
COMMIT
# Completed on Tue Apr 22 11:37:52 2014
#service iptables save
#service iptables restart
相关推荐
bluecarrot 2020-11-23
Attend 2020-11-17
ZHAICAN 2020-11-16
codedecode 2020-11-14
zhangbingb 2020-11-12
ykmail 2020-11-11
futurezone 2020-11-06
rikeyone 2020-11-04
橄榄 2020-11-04
WenCoo 2020-10-31
farwang 2020-11-25
星愿心愿 2020-11-24
tianhuak 2020-11-24
zhjn0 2020-11-24
昭君出塞 2020-11-23
linuxwcj 2020-10-21
以梦为马不负韶华 2020-10-20