networking - How to set up simple static Ethernet connection?

17
2014-04
  • Yang

    System A has Wi-Fi Internet access and an Ethernet port, while System B has just an Ethernet port. I connected the ports directly to each other. Both are fairly modern desktop PCs running Ubuntu 10.04.

    On A I ran:

    $ sudo ip addr add 192.168.0.1/24 dev eth0
    
    $ ip route
    10.66.225.0/24 dev ra0  proto kernel  scope link  src 10.66.225.153  metric 2 
    192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.1 
    169.254.0.0/16 dev ra0  scope link  metric 1000 
    default via 10.66.225.1 dev ra0  proto static
    

    On B I ran:

    $ sudo ip addr add 192.168.0.2/24 dev eth0
    

    However, when I now try to ping 192.168.0.2 from .1, I get:

    $ ping 192.168.0.2
    PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
    From 192.168.0.1 icmp_seq=1 Destination Port Unreachable
    From 192.168.0.1 icmp_seq=2 Destination Port Unreachable
    

    Any hints? TIA.

  • Answers
  • jdthood

    Try using an Ethernet hub or switch to connect the two machines. If the machines are old then you can't use a conventional UTP cable to connect them. (You can use a crossover cable.) Even if the machines are new and are equipped with Auto-MDIX, what can happen is that both machines have their Ethernet ports switched off and niether one will switch its port on until connected to a peer with an enabled port.

  • Yang

    And like magic, I just pressed up enter to retry the same command again some 10m later, and it works. I'll still mark another answer as accepted if someone can explain why this happened.

    Update: Just tried doing the same thing again, and once more I'm getting Destination Host Unreachable errors, except this time it's been hours and the problem hasn't gone away.


  • Related Question

    11.10 - how to ping & use specific network card
  • One Zero

    i have 3 network cards , 1 Lan (wired) , 1 wireless network card & 1 is wireless usb

    how do i ping from specific network card ?

    & how do i use specific network card for specific application

    example

    i want to ping google from wlan0 
    

    example for specific application

    i want to use firefox or transmission from wan1
    

    UPDATED

    Lan ip 192.168.0.2 > Working Properly enter image description here

    Wlan1 ip 192.168.0.3

    enter image description here

    pin -I wlan1 google.com
    

    UPDATE

    Try pasting the output of route -n and/or ip route. Seems to me that the wlan1 interface hasn't a valid gateway configured. –@MrShunz

    one@onezero:~$ route -n 
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
    169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
    172.16.221.0    0.0.0.0         255.255.255.0   U     0      0        0 vmnet8
    192.168.0.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
    192.168.0.0     0.0.0.0         255.255.255.0   U     2      0        0 wlan1
    192.168.48.0    0.0.0.0         255.255.255.0   U     0      0        0 vmnet1
    one@onezero:~$ ip route
    default via 192.168.0.1 dev eth0  proto static 
    169.254.0.0/16 dev eth0  scope link  metric 1000 
    172.16.221.0/24 dev vmnet8  proto kernel  scope link  src 172.16.221.1 
    192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.2  metric 1 
    192.168.0.0/24 dev wlan1  proto kernel  scope link  src 192.168.0.3  metric 2 
    192.168.48.0/24 dev vmnet1  proto kernel  scope link  src 192.168.48.1 
    

  • Related Answers
  • Mr Shunz

    ping has a specific switch to set source interface: -I. As found in the manpage:

     -I interface address
              Set source address to specified interface address. Argument may be  numeric  
              IP  address  or  name  of device.
              When pinging IPv6 link-local address this option is required.
    

    As an example

    $ ping -I wlan0 8.8.8.8
    

    ping 8.8.8.8 through wlan0 interface.

    Forcing an interface for a specific application needs some more work. You can find a solution in this superuser.com question and in this article linked in the answer.

    UPDATE

    The methods i exposed in this answer show how to force ping to use a specific interface. And links to some articles on how to force a generic program to use a specific interface.

    Now, for all this to work, you have to configure some "advanced" routing. As you can see from the output of route -n you have multiple networks, but only ONE gateway to the Internet. That is good, as multiple gateway routing is quite an advanced topic and somewhat difficult to handle well.

    This goes beyond what you asked in the original question. I suggest you to post a new question here or on Server Fault asking how to configure and manage multiple internet gateways on multiple network interfaces.

    Or, better yet, try googling it ;) Also check the LARTC site for advanced linux routing configurations.