我在linux上的networking接口知识是有限的,所以我希望有人能帮我找出最好的解决scheme,我已经无意中造成的问题。
启动后,我的工作站上的回环设备似乎不存在。 需要回送地址的东西(例如在Eclipse中运行JUnittesting套件)无法正常工作。 不过,直到最近,我还没有弄清楚iptables将端口80转发到端口8080,所以这可能是我所做的,但我不知道如何解决这个问题。到目前为止所有谷歌没有发现任何指针(我可能不知道正确的search条件…)
首先, /etc/network/interfaces :
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 pre-up iptables-restore /etc/iptables.conf post-down /etc/iptables-flush-all
现在,启动我的机器后:
$ sudo ifconfig eth0 Link encap:Ethernet HWaddr 00:24:e8:25:90:5d inet addr:10.33.1.106 Bcast:10.33.1.255 Mask:255.255.255.0 inet6 addr: fe80::224:e8ff:fe25:905d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:500239 errors:0 dropped:0 overruns:0 frame:0 TX packets:334565 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:617321176 (588.7 MiB) TX bytes:36019254 (34.3 MiB) Interrupt:26 Base address:0x8000
如果我运行ifconfig lo 127.0.0.1 ,那么每一件事情都很好, ifconfig的输出变成:
$ sudo ifconfig eth0 Link encap:Ethernet HWaddr 00:24:e8:25:90:5d inet addr:10.33.1.106 Bcast:10.33.1.255 Mask:255.255.255.0 inet6 addr: fe80::224:e8ff:fe25:905d/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:606221 errors:0 dropped:0 overruns:0 frame:0 TX packets:407173 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:767892736 (732.3 MiB) TX bytes:42051623 (40.1 MiB) Interrupt:26 Base address:0x8000 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:65 errors:0 dropped:0 overruns:0 frame:0 TX packets:65 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:35668 (34.8 KiB) TX bytes:35668 (34.8 KiB)
那么,谁能帮我弄清楚我已经做了什么来打破我的环回地址?
编辑0 : /etc/iptables.conf内容:
chris@PC:~$ sudo cat /etc/iptables.conf # Generated by iptables-save v1.4.8 on Thu Nov 10 17:01:44 2011 *nat :PREROUTING ACCEPT [2:440] :POSTROUTING ACCEPT [2:102] :OUTPUT ACCEPT [1:58] -A PREROUTING -d 127.0.0.1/32 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080 -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination :8080 -A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080 COMMIT # Completed on Thu Nov 10 17:01:44 2011 # Generated by iptables-save v1.4.8 on Thu Nov 10 17:01:44 2011 *mangle :PREROUTING ACCEPT [4787:2521834] :INPUT ACCEPT [4544:2507689] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [4190:913164] :POSTROUTING ACCEPT [4117:908160] COMMIT # Completed on Thu Nov 10 17:01:44 2011 # Generated by iptables-save v1.4.8 on Thu Nov 10 17:01:44 2011 *filter :INPUT ACCEPT [2699:1514101] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [2525:612477] COMMIT # Completed on Thu Nov 10 17:01:44 2011
chris @ PC:〜$ sudo iptables -L -t filter
Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
chris @ PC:〜$ sudo iptables -L -t mangle
Chain PREROUTING (policy ACCEPT) target prot opt source destination Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain POSTROUTING (policy ACCEPT) target prot opt source destination
chris @ PC:〜$ sudo iptables -L -t nat
Chain PREROUTING (policy ACCEPT) target prot opt source destination Chain POSTROUTING (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
编辑1 :在我的/etc/network/interfaces中注释掉eth0的pre-up和post-down行,似乎可以消除这个问题。
在将/etc/network/interfaces改为这个之后,我的环回地址在引导过程中被正确地configuration了:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 #pre-up iptables-restore /etc/iptables.conf #post-down /etc/iptables-flush-all
这两行是用来加载和卸载iptables规则,当接口被启用和禁用。 我读过这是在Debian中configuration防火墙的一个比在启动时加载所有规则更好的方法。
/etc/iptables-flush-all是:
chris @ PC:〜$ sudo cat /etc/iptables-flush-all
#!/bin/sh iptables --flush iptables -t nat --flush iptables -t mangle --flush iptables -t filter --flush
没有你的防火墙加载它工作吗?
顺便说一句,“ifconfig”已被弃用; 包括诊断在内的所有内容最好使用“ip”。 不是说我认为这与你的问题有关。
在我的情况下,正确的configuration/ etc / hosts的问题。
使用命令主机名获取您的主机名,并以这种方式设置/ etc / hosts:
127.0.0.1 localhost 127.0.1.1 HOSTNAME
在我的情况下,这是https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=739251 …我已经得到了在ip pre-up的iptables恢复,它包括-A INPUT -i! lo -d 127.0.0.0/8 -j拒绝哪个是现在被弃用的语法…
所以,如果你有线
pre-up iptables-restore /etc/iptables.up.rules
在/ etc / network / interfaces中,检查规则是否正确。
在739251错误的具体情况下,更换
-Ainput-i! lo -d 127.0.0.0/8 -j拒绝
同
– input! -i lo -d 127.0.0.0/8 -j拒绝