2

I have two Ubuntu PCs whose network cards connected directly to each other with cross-over cable. I have assigned ip addresses manually to their interfaces using command similar to

 ifconfig eth0 192.168.2.1 up

The problem is that every time I physically disconnect those PCs, the connection goes down and next time when I connect it back, the IP addresses are lost. Also whatever applications I have bound to those addresses before disconnect needs restarting two. Is there a way to keep network interfaces UP during physical cable disconnect so the apps which create listening sockets on those addresses, would not need to be restarted after re-connect?

  • Its not possible for a connection to stay during disconnects. That's just the way Ethernet works. You can ensure that when you reconnect you always have the same IP address: Seppo's answer tells you how to do this but when you disconnect you don't have an IP address. The card may be reporting the same IP address but any open connections will be broken and have to be re-established. – Warren Hill Oct 3 '13 at 16:20
4

Edit your /etc/networking/interfaces and add:

iface eth0 inet static
    address 192.168.2.1
    netmask 255.255.255.0

Then eth0 has static ip always.

More info on configuring interfaces with man interfaces

You can also use Network Connections graphical setup tool from your system preferences. You can configure network-manager to use static ip-addresses from there.

  • But will it stay UP during disconnects? Like would the software be able to bind to that ip address, while the cable is not physically plugged in into the network card? – Ma99uS Jun 23 '11 at 12:28
  • I'm not sure. Can you test it? – Seppo Erviälä Jun 23 '11 at 13:11
  • I will try it and report back – Ma99uS Jun 23 '11 at 13:16
2

NetworkManager now seems to support an config option to ignore the carrier-state of interfaces and keep them up during disconnects:

NetworkManager.conf man page clarifies how to use the ignore-carrier option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.