开发者

the wired network connection is active ,but can't connect to the internet

The operating system is Ubuntu10.04. The icon of network connection on the panel shows the wired network connection is active, but I can't access to the Internet. So I set the network configuration manually.I changed the /etc/resolv.conf as below:

nameserver 202.112.14.151

202.112.14.151 is my school's DNS server's IP. 192.168.2.1 is router' address. I also changed the /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

And /var/run/network/ifstate:

 lo=lo
 eth0=eth0

My classmates (we'are in the sam开发者_运维问答e room and use the same router) used

address:192.168.2.254
netmask:255.255.255.0
gateway:192.168.2.1   
DNS server:202.112.14.151 

to configure the network on Windows xp can access to the Internet. I typed the command ping 192.168.2.1 but it reminds me the host 192.168.2.1 is unreachable. Do I neglect something? Please tell me, Thx!


If 192.168.2.1 is unreachable, there is something wrong with your local area network. This could mean your adapter / cable, but you say the panel shows an active connection. Are you connected to the right switch / right port on the switch? Are you using the right kind of cable (try changing)?

Try ping 192.168.2.255 to see if you can reach any nodes on the network.


Here The Solution ` public static void main(String[] args) { String 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();
    }
}`

Output

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜