我编写了一个 Java服务器应用程序,它侦听来自客户端的数据,然后写入数据库。我在带有两个网卡的linux Ubuntu 12.04计算机上运行该应用程序。虽然我在启用单个网络接口的情况下连接到网络,但它工作得非常好,但是当我启用两个网络接口时,我只能从连接到 eth0 的客户端接收数据。
我的服务器的代码几乎是经典的:
String address = "0.0.0.0";
serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress(address,port));
while (true) {
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
System.out.println("\n----Connection accepted----");
ConnectionHandler handler = new ConnectionHandler(clientSocket, mysql);
Thread handlerThread = new Thread(handler);
handlerThread.setPriority(Thread.NORM_PRIORITY);
handlerThread.start();
catch(Exception exc){
//catch statement
}
}
问题很奇怪,因为地址“0.0.0.0”应该创建一个侦听所有接口的套接字。
有什么可以建议我如何解决这个问题?
编辑:可能问题出在 SO 设置中。
这是我的 /etc/network/interfaces 文件的内容:
auto lo
iface lo inet loopback
这是sudo lshw -class network命令的结果
~$ sudo lshw -class network
[sudo] password for administrator:
*-network
description: Ethernet interface
product: I210 Gigabit Network Connection
vendor: Intel Corporation
physical id: 0
bus info: pci@0000:02:00.0
logical name: eth0
version: 03
serial: 90:1b:0e:0b:11:22
size: 100Mbit/s
capacity: 1Gbit/s
width: 32 bits
clock: 33MHz
capabilities: pm msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=igb driverversion=5.0.5-k duplex=full firmware=3.16, 0x800005ae ip=10.0.0.100 latency=0 link=yes multicast=yes port=twisted pair speed=100Mbit/s
resources: irq:18 memory:f7a00000-f7a7ffff ioport:e000(size=32) memory:f7a80000-f7a83fff
*-network
description: Ethernet interface
product: I210 Gigabit Network Connection
vendor: Intel Corporation
physical id: 0
bus info: pci@0000:03:00.0
logical name: eth1
version: 03
serial: 90:1b:0e:0b:0f:25
size: 100Mbit/s
capacity: 1Gbit/s
width: 32 bits
clock: 33MHz
capabilities: pm msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=igb driverversion=5.0.5-k duplex=full firmware=3.16, 0x800005b0 ip=192.168.150.100 latency=0 link=yes multicast=yes port=twisted pair speed=100Mbit/s
resources: irq:19 memory:f7900000-f797ffff ioport:d000(size=32) memory:f7980000-f7983fff