0

eth0 is managed by the network manager icon and connects using dhcp when it detects a network cable.

However, very occasionally I want to connect to some special-purpose computers with static IP addresses using a direct ethernet connection (cross-over). Then I set

sudo ifconfig eth0 10.90.90.91

or

sudo ifconfig eth0:1 10.90.90.91

and can connect to the computer in question.

However, after a minute or so, that eth0 looses that IP address and my connections hang until I repeat the ifconfig step.

Right now I'm using a loop and repeat setting the IP address every 10 seconds.

But I wonder if I can tell the network manager (which I suspect is the culprit) somehow to, right now, not try to manage eth0 until I need it again to do it.

Edit: The question How do I set an extra IP for an existing interface? differs from mine. That question wants to perpetuate the setting across reboots. I'm not interested in that. I only want to have that fixed IP address for eth0 very occasionally. Usually the dhcp procedure is ok for me. Only sometimes I want it to back off.

2 Answers2

1

Use ifdown (and ifup). See man ifdown. If you don't want use /etc/network/interfaces, after ifdown you can use ifconfig to configure by hand. From man ifdown:

DESCRIPTION
       The   ifup   and   ifdown  commands  may  be  used  to  configure  (or,
       respectively,  deconfigure)  network  interfaces  based  on   interface
       definitions  in  the file /etc/network/interfaces.  ifquery command may
       be used to parse interfaces configuration.
waltinator
  • 36,399
  • No, does not help: ifdown eth0 results in" ifdown: interface eth0 not configured". eth0 does not show up at all in /etc/network/interfaces. That only manages lo. – Ludwig Schulze Apr 10 '16 at 19:26
  • you need to use ifdown -f eth0 ( to force it) , since ifdown & ifconfig usage inconsistent . As given below. The program keeps records of whether network interfaces are up or down. Under exceptional circumstances these records can become inconsistent with the real states of the interfaces. For example, an interface that was brought up using ifup and later deconfigured using ifconfig will still be recorded as up. To fix this you can use the --force option to force ifup or ifdown to run configuration or deconfiguration commands despite what it considers the current state of the interface to be – buddy Feb 25 '21 at 14:30
1

If I understand correctly you want sometimes a different configuration for your network and you want to use Network Manager - I presume GUI.

So you open the network manager, add another connection (call it static address or so). Now configure this connection with the settings you want, don't set Automatically connect to this network..

screenshot general enter image description here

Whenever you need this special setting just select it from the Network Manager menu.

guntbert
  • 13,134
  • I may be missing something here. Actually I have tried to do what you suggest - add another network configuration for ethernet by clicking on the network manager icon, selecting "edit connections", and set the new connection so that it does not autoconnect. However, I do not see a way to activate this connection when I need it. This connection does not show up in the menu of the network manager icon in unity. – Ludwig Schulze Apr 10 '16 at 20:05
  • @LudwigSchulze You must add it as the correct type ethernet vs. wifi - when I have no ethernet connection at all my ethfix doesn't show up either. – guntbert Apr 10 '16 at 20:21
  • Hmm. My connection with the static ip but no autoconnect lives in the "Ethernet" category, right under "Wired Connection 1" which is my DHCP connection and which set to autoconnect. I just checked if maybe my static ethernet shows up when a network cable is connected, but no, only my dhcp connection shows up in the icon menu and the icon shows the "connection in progress" animation, trying to connect using dhcp, but to no avail, as the special purpose PC with the static IP does not have a DHCP server. – Ludwig Schulze Apr 10 '16 at 20:22
  • @LudwigSchulze just for a test: try nmcli c (on CLI) -- does the connectio show up there? If yes you could try to restart network Manager. – guntbert Apr 10 '16 at 20:26
  • yes nmcli c shows the static connection – Ludwig Schulze Apr 10 '16 at 20:31
  • @LudwigSchulze then try nmcli c up ethstatic. – guntbert Apr 10 '16 at 20:34
  • Will try tomorrow with ethernet cable to target computer. Right now I am not near the target and: nmcli c up uuid "4bd93064-e413-42ae-8530-44f9ddb7bdd8" -> Error: No suitable device found: no device found for connection 'Static Ethernet 10'. Hopefully ethernet cable makes a difference. – Ludwig Schulze Apr 10 '16 at 21:09
  • With connection cable, still same error "No device found for connection". But this made no sense. I checked the connection settings if there was a way to specify which network device and sure there is a setting where you can select eth0. But in my connection, some other strange MAC address was selected. I do not knnow how. I could change that to eth0 and now it works! – Ludwig Schulze Apr 11 '16 at 04:35