iface eth0上有两个ip地址:
eth0 Link encap:Ethernet HWaddr 00:19:99:a4:14:08 inet addr:85.25.152.115 Bcast:85.25.152.255 Mask:255.255.255.0 inet6 addr: fe80::219:99ff:fea4:1408/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:233866 errors:0 dropped:0 overruns:0 frame:0 TX packets:145186 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:175800889 (167.6 MiB) TX bytes:38033903 (36.2 MiB) Interrupt:18 eth0:1 Link encap:Ethernet HWaddr 00:19:99:a4:14:08 inet addr:85.25.248.216 Bcast:85.25.248.255 Mask:255.255.255.192 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:18
我有一个virtualbox guest的内部虚拟iface:
tap0 Link encap:Ethernet HWaddr ae:ba:ce:d7:7d:bd inet addr:10.0.1.1 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::acba:ceff:fed7:7dbd/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:111 overruns:0 carrier:0 collisions:0 txqueuelen:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
10.0.1.1是VM(10.0.1.2)的GW。 从10.0.1.2到Internet的转发工作正常,但是当我试图将所有端口从85.25.248.216(eth0:1)redirect到10.0.1.2时,它会失败:
iptables -t nat -A PREROUTING -d 85.25.248.216 -j DNAT --to-destination 10.0.1.2 nmap -A -v 85.25.248.216 <...> PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 5.8p1 Debian 4 (protocol 2.0) | ssh-hostkey: 1024 4e:3e:ce:86:24:f8:54:7a:68:67:be:57:92:62:00:f0 (DSA) |_2048 36:f5:0d:4c:1b:58:b8:f9:ff:0f:47:ba:88:43:69:bd (RSA) 10000/tcp open http MiniServ 1.540 (Webmin httpd) |_html-title: Site doesn't have a title (text/html). Device type: general purpose Running: Linux 2.6.X OS details: Linux 2.6.19 - 2.6.31 india827:~# iptables --list -t nat Chain PREROUTING (policy ACCEPT) target prot opt source destination DNAT all -- anywhere static-ip-85-25-248-216.inaddr.intergenia.de to:10.0.1.2 DNAT tcp -- anywhere static-ip-85-25-248-216.inaddr.intergenia.de tcp dpt:3389 to:10.0.1.2 Chain INPUT (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination DNAT all -- anywhere static-ip-85-25-248-216.inaddr.intergenia.de to:10.0.1.2 Chain POSTROUTING (policy ACCEPT) target prot opt source destination MASQUERADE all -- anywhere anywhere SNAT all -- anywhere anywhere to:85.25.248.216
虚拟机在Windows上,至less要打开3389(RDP),但我当然也不能连接到它。 错误在哪里?
新规则:
iptables -t nat -A PREROUTING -d 85.25.248.216 -j DNAT --to-destination 10.0.1.2 iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -m conntrack --ctstate NEW -d 10.0.1.2 -j ACCEPT
结果是一样的…
iptables命令是正确的,所以它必须是在上下文中的东西。 我会尝试猜测。
IP转发未启用。
cat /proc/sys/net/ipv4/ip_forward
应该给1的值。 如果不是,则将其设置为1
echo 1 > /proc/sys/net/ipv4/ip_forward
你正在打10.0.1.2到85.25.152.115
iptables --list -t nat
应该显示出来。
为什么不使用Virtualbox NAT转发?
http://www.virtualbox.org/manual/ch06.html#natforward
然后调整iptables来打开主机端口。 您已经在Virtualbox中运行NAT路由器,为什么要运行两个?