操作系统是Ubuntu10.04。面板上的network connection
图标显示
有线网络连接处于活动状态,但我无法访问Internet。所以我手动设置了网络配置。我更改了/etc/resolv.conf
,如下所示:
nameserver 202.112.14.151
202.112.14.151是我学校的DNS服务器的IP。 192.168.2.1是路由器的地址。我还更改了/etc/network/interfaces
:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.2.107
netmask 255.255.255.0
gateway 192.168.2.1
/var/run/network/ifstate
:
lo=lo
eth0=eth0
我的同学(我们在同一个房间并使用相同的路由器)使用
address:192.168.2.254
netmask:255.255.255.0
gateway:192.168.2.1
DNS server:202.112.14.151
在Windows xp
上配置网络可以访问Internet。
我输入了命令ping 192.168.2.1
,但它提醒我主机192.168.2.1无法访问。我是否疏忽了什么?请告诉我,Thx!
答案 0 :(得分:0)
如果无法访问192.168.2.1,则您的局域网出现问题。这可能意味着您的适配器/电缆,但您说面板显示活动连接。您是否连接到交换机上的右侧交换机/右侧端口?您使用的是合适的电缆(尝试更换)吗?
尝试ping 192.168.2.255
查看您是否可以访问网络上的任何节点。
答案 1 :(得分:0)
这是解决方案 `public static void main(String [] args){ 字符串IP;
try {
InetAddress ip = InetAddress.getLocalHost();
IP=ip.getHostAddress();
//Host NET ID
System.out.println("Current IP address : " + IP);
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
//Type
System.out.println("Type Eth0/wlan :"+network.getName());
//SubNet Prefix
System.out.println("SubNet ID :"+network.getInterfaceAddresses().get(0).getNetworkPrefixLength());
System.out.println();
//HostName
System.out.println("HostName :"+ip.getHostName());
//MAC
System.out.print("Current MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
System.out.println(sb.toString());
InetAddress i = InetAddress.getLocalHost();
byte[] ip1 = i.getAddress();
for (int b = 0; b <255;b++) {
ip1[3] = (byte)b;
InetAddress address = InetAddress.getByAddress(ip1);
if (address.isReachable(3000)) {
System.out.println("\tIP :"+address.getHostAddress());
NetworkInterface network1 = NetworkInterface.getByInetAddress(address);
System.out.println("Type Eth0/wlan :"+network.getName());
System.out.println();
} else if (!address.getHostAddress().equals(address.getHostName())) {
System.out.println("\tIP :"+address.getHostAddress());
} else {
System.out.println("NO");
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}`