当前位置: 技术问答>linux和unix
求助有关端口映射的问题 100分
来源: 互联网 发布时间:2016-04-25
本文导语: 一个端口映射问题,原帖地址 原帖地址 这里我把情况完全描述下,希望各位高人指点一二。 问题核心:内网(192.168.1.x)通过一个双网卡机器(redhat as4,以下称网关)连接到外网,外网ip:210.28.132.80。现在我在内...
一个端口映射问题,原帖地址
原帖地址
这里我把情况完全描述下,希望各位高人指点一二。
问题核心:内网(192.168.1.x)通过一个双网卡机器(redhat as4,以下称网关)连接到外网,外网ip:210.28.132.80。现在我在内网.2的机器上开了web服务,在网
关上用iptables做端口映射.80:80到.2:80。现在外网可以通过210.28.132.80访问web服务,内网则不行,只能通过192.168.1.2访问web服务。
请问如何配置(可以考虑配置本地)才能让内网也可以通过210.28.132.80访问web服务。
再复杂一点假设我做的端口映射是210.28.132.80:8080 192.168.1.80:80,怎么配置使内外网都能使用210.28.132.80:8080访问。
现在配置情况:内网可以通过网关连到外网。
我会尽可能的把问题和环境描述清楚,因为自己对网络配置和linux都不熟悉,这些配置也都是看网上依葫芦画瓢做的。所以还恳请各位能给出大概的解决步骤,谢谢。
这个问题我已经发了一段时间了,感谢期间提供帮助的网友,不过问题还没最终解决。设置100分,略表心意。
iptables 配置,ip_forward已经打开
[code=INIFile][root@localhost ~]# cat /etc/sysconfig/iptables
*nat
:PREROUTING ACCEPT [76:10098]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [1:88]
-A POSTROUTING -o eth0 -j MASQUERADE
### port mapping
-A PREROUTING -d 210.28.132.80 -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
### end port mapping
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
# -A INPUT -j RH-Firewall-1-INPUT
# -A FORWARD -j RH-Firewall-1-INPUT
# -A RH-Firewall-1-INPUT -i lo -j ACCEPT
# -A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
# -A RH-Firewall-1-INPUT -p 50 -j ACCEPT
# -A RH-Firewall-1-INPUT -p 51 -j ACCEPT
# -A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
# -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
# -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
### port mapping
-A FORWARD -d 192.168.1.69 -p tcp -m tcp --dport 80 -j ACCEPT
### end port mapping
COMMIT
[root@localhost ~]# [/code]
网卡配置:用到的是eth0连外网,eth2连内网。eth1未使用(光纤接口)
[code=INIFile][root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0B:DB:5C:78:DE
inet addr:210.28.132.80 Bcast:210.28.132.255 Mask:255.255.255.0
inet6 addr: fe80::20b:dbff:fe5c:78de/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:218832106 errors:0 dropped:0 overruns:0 frame:0
TX packets:169372427 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2006628648 (1.8 GiB) TX bytes:1439371908 (1.3 GiB)
Base address:0xecc0 Memory:fe7e0000-fe800000
eth1 Link encap:Ethernet HWaddr 00:03:47:9A:55:AE
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::203:47ff:fe9a:55ae/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Memory:fe5e0000-fe600000
eth2 Link encap:Ethernet HWaddr 00:1E:58:45:8D:B5
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: 2002:3ac0:2270:6:21e:58ff:fe45:8db5/64 Scope:Global
inet6 addr: fe80::21e:58ff:fe45:8db5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:171604141 errors:0 dropped:0 overruns:0 frame:0
TX packets:217218013 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1691229535 (1.5 GiB) TX bytes:1826825334 (1.7 GiB)
Interrupt:50 Memory:fe1f4000-0
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:7120 errors:0 dropped:0 overruns:0 frame:0
TX packets:7120 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3694433 (3.5 MiB) TX bytes:3694433 (3.5 MiB)
[root@localhost ~]#
[/code]
原帖地址
这里我把情况完全描述下,希望各位高人指点一二。
问题核心:内网(192.168.1.x)通过一个双网卡机器(redhat as4,以下称网关)连接到外网,外网ip:210.28.132.80。现在我在内网.2的机器上开了web服务,在网
关上用iptables做端口映射.80:80到.2:80。现在外网可以通过210.28.132.80访问web服务,内网则不行,只能通过192.168.1.2访问web服务。
请问如何配置(可以考虑配置本地)才能让内网也可以通过210.28.132.80访问web服务。
再复杂一点假设我做的端口映射是210.28.132.80:8080 192.168.1.80:80,怎么配置使内外网都能使用210.28.132.80:8080访问。
现在配置情况:内网可以通过网关连到外网。
我会尽可能的把问题和环境描述清楚,因为自己对网络配置和linux都不熟悉,这些配置也都是看网上依葫芦画瓢做的。所以还恳请各位能给出大概的解决步骤,谢谢。
这个问题我已经发了一段时间了,感谢期间提供帮助的网友,不过问题还没最终解决。设置100分,略表心意。
iptables 配置,ip_forward已经打开
[code=INIFile][root@localhost ~]# cat /etc/sysconfig/iptables
*nat
:PREROUTING ACCEPT [76:10098]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [1:88]
-A POSTROUTING -o eth0 -j MASQUERADE
### port mapping
-A PREROUTING -d 210.28.132.80 -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
### end port mapping
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
# -A INPUT -j RH-Firewall-1-INPUT
# -A FORWARD -j RH-Firewall-1-INPUT
# -A RH-Firewall-1-INPUT -i lo -j ACCEPT
# -A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
# -A RH-Firewall-1-INPUT -p 50 -j ACCEPT
# -A RH-Firewall-1-INPUT -p 51 -j ACCEPT
# -A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
# -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
# -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
### port mapping
-A FORWARD -d 192.168.1.69 -p tcp -m tcp --dport 80 -j ACCEPT
### end port mapping
COMMIT
[root@localhost ~]# [/code]
网卡配置:用到的是eth0连外网,eth2连内网。eth1未使用(光纤接口)
[code=INIFile][root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0B:DB:5C:78:DE
inet addr:210.28.132.80 Bcast:210.28.132.255 Mask:255.255.255.0
inet6 addr: fe80::20b:dbff:fe5c:78de/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:218832106 errors:0 dropped:0 overruns:0 frame:0
TX packets:169372427 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2006628648 (1.8 GiB) TX bytes:1439371908 (1.3 GiB)
Base address:0xecc0 Memory:fe7e0000-fe800000
eth1 Link encap:Ethernet HWaddr 00:03:47:9A:55:AE
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::203:47ff:fe9a:55ae/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Memory:fe5e0000-fe600000
eth2 Link encap:Ethernet HWaddr 00:1E:58:45:8D:B5
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: 2002:3ac0:2270:6:21e:58ff:fe45:8db5/64 Scope:Global
inet6 addr: fe80::21e:58ff:fe45:8db5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:171604141 errors:0 dropped:0 overruns:0 frame:0
TX packets:217218013 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1691229535 (1.5 GiB) TX bytes:1826825334 (1.7 GiB)
Interrupt:50 Memory:fe1f4000-0
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:7120 errors:0 dropped:0 overruns:0 frame:0
TX packets:7120 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3694433 (3.5 MiB) TX bytes:3694433 (3.5 MiB)
[root@localhost ~]#
[/code]
|
用下面两条规则:
iptables -t nat -A PREROUTING -d 210.28.132.80 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -d 192.168.1.2 -p tcp -m tcp --dport 80 -j SNAT --to-source 192.168.1.1
而不要再用你的那条规则:
-A PREROUTING -d 210.28.132.80 -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
如果是8080端口:
iptables -t nat -A PREROUTING -d 210.28.132.80 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.168.1.2:80
iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -d 192.168.1.2 -p tcp -m tcp --dport 80 -j SNAT --to-source 192.168.1.1
iptables -t nat -A PREROUTING -d 210.28.132.80 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -d 192.168.1.2 -p tcp -m tcp --dport 80 -j SNAT --to-source 192.168.1.1
而不要再用你的那条规则:
-A PREROUTING -d 210.28.132.80 -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
如果是8080端口:
iptables -t nat -A PREROUTING -d 210.28.132.80 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.168.1.2:80
iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -d 192.168.1.2 -p tcp -m tcp --dport 80 -j SNAT --to-source 192.168.1.1