为什么只有debian返回127.0.0.1

时间:2012-09-05 18:19:22

标签: linux dns

我创建了一部分代码来获取本地主机和当前的ip地址,我在windows,linux(opensusedebian),mac上尝试这个,每个人都返回他的ip地址,除了debian返回127.0.0.1并且我已连接到互联网。

因为我希望以下地址

192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4

任何帮助。

我的代码是用java编写的,并在不同的平台上进行测试。

我使用java中的inetaddress

来创建代码

EDIt:

sbin / ipconfig OUTPU

eth0      Link encap:Ethernet  HWaddr 00:1e:33:e0:56:af  
          inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21e:33ff:fee0:56af/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10549 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12135 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8705530 (8.3 MiB)  TX bytes:1857590 (1.7 MiB)
          Interrupt:20 Memory:fc600000-fc620000 

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:270 errors:0 dropped:0 overruns:0 frame:0
          TX packets:270 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:22696 (22.1 KiB)  TX bytes:22696 (22.1 KiB)

vmnet1    Link encap:Ethernet  HWaddr 00:50:56:c0:00:01  
          inet addr:192.168.68.1  Bcast:192.168.68.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:159 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

vmnet8    Link encap:Ethernet  HWaddr 00:50:56:c0:00:08  
          inet addr:172.16.79.1  Bcast:172.16.79.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fec0:8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 70:1a:04:a5:86:5a  
          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)

等/宿主

127.0.0.1 localhost
127.0.1.1 debiam.domain debiam

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

关于src代码它只是inetaddress

2 个答案:

答案 0 :(得分:2)

取决于具体实现,它取决于您在linux中检查的接口。 lo接口将为您提供127.0.0.1。您可能有一个类似'eth0'或'eth3'的界面,它使用您期望的IP地址。

答案 1 :(得分:1)

在linux中的推荐

ifconfig 

你提供这个细节

eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx  
      inet addr:192.168.1.200  Bcast:192.168.1.255  Mask:255.255.255.0
      inet6 addr: fe80::1e6f:65ff:fed5:8a16/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:3363918 errors:0 dropped:0 overruns:0 frame:0
      TX packets:1892239 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:4890880074 (4.8 GB)  TX bytes:150386146 (150.3 MB)
      Interrupt:43 Base address:0xa000 

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:160038 errors:0 dropped:0 overruns:0 frame:0
      TX packets:160038 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:64218501 (64.2 MB)  TX bytes:64218501 (64.2 MB)

wlan0     Link encap:Ethernet  HWaddr xx.xx.xx.xx.xx.xx  
      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)

ip 127.0.0.1在lo(loopback,localhost)接口中,但在另一个接口中,例如eth0,你的ip是xxx.xxx.xxx.xxx或ipv6。