5

I'm encountering a problem on a sever with two ethernet interfaces(etho and eth1), it runs linux-ubuntu-server. I need eth1 not make any dhcp request, becouse I need it to be only a listening interface, obviusly I need eth0 running normally. So how can i disable any dhcpclient ation over eth1?

thank in advance.

Lopoc
  • 201
  • 1
  • 2
  • 4

5 Answers5

7

Something like:

auto lo eth0 eth1

iface lo inet loopback

iface eth1 inet static
        address 192.168.32.130
        netmask 255.255.255.0
        gateway 192.168.32.1

in your /etc/network/interfaces config file will assign your eth1 a static IP address.

YasirA
  • 211
  • 1
  • 4
  • 1
    I need eth1 to be mute, no IP at all, probably i could set in /etc/network/interfaces address to 0.0.0.0 –  Jun 04 '10 at 09:15
  • 2
    @Lopoc: If you want `eth1` to be disabled completely, you may try to leave only interfaces you need to be up in `/etc/network/interfaces`: `auto lo eth0`. If you want your interface to reject all incoming connections you may use `iptables`, `ipfw`. – YasirA Jun 04 '10 at 09:36
5

Sometimes even with correct /etc/network/interfaces file, dhclient continues to request IP addresses on static interfaces. The problem might be the existence of old /var/lib/dhcp/dhclient.*.leases files with incorrect information. Just kill dhclient, remove those files, and start it anew (by doing ifdown/ifup on DHCP interfaces).

Cory Knutson
  • 1,876
  • 13
  • 20
lvd
  • 151
  • 1
  • 2
1

For modern Linux OSes this can be controlled by Network Manager:

  • In RHEL: change the BOOTPROTO=dhcp line in the file /etc/sysconfig/network-scripts/ifcfg-eth1 to BOOTPROTO=static, then restart the network services.

  • In Debian: change the method=auto line to method=static in the file /etc/NetworkManager/system-connections/Wired connection 1, then restart the network services.

Shōgun8
  • 215
  • 1
  • 11
  • The folder /etc/sysconfig doesn't exist on debian and related, like ubuntu, raspberry pi os, etc. Please consider to revise it. – scegg May 07 '22 at 02:29
-1

Although the question is very old, since I found difficult to find the right answer, I think it is still pertinent to answer. If I understand well your question, I think the best solution is using the two options in dhcpcd.conf which are designed for that. Here is what the doc says :

allowinterfaces pattern : When discovering interfaces, the interface name must match pattern which is a space or comma separated list of patterns passed to fnmatch(3). If the same interface is matched in denyinterfaces then it is still denied.

denyinterfaces pattern : When discovering interfaces, the interface name must not match pattern which is a space or comma separated list of patterns passed to fnmatch(3).

Example : denyinterfaces eth0

-2

if you don't want to add a static ip on this interface, maybe you have to delete the IP assigned by DHCP client.

Running this script will remove the ip on eth0.

#!/bin/sh
localip=`ip addr list dev eth0 | grep "inet " | sed 's/\(^\s*inet\s\)\([0-9\.]*\)\([\s\/].*\)/\2/'`
if [[$ip != ""]]; then
sudo ip addr del $localip dev eth0
fi

You need to run it manually or set it into crontab. Or, try to call it after IP assigned, but I don't know how to hook that. After the IP address removed, it works like the dhcp client is disabled on this interface.

Note: This is only a workaround by removing the effect of DHCP client on the specified interface, not really disable it. It works on my solution which required the interface is UP without ANY ip address assigned.

scegg
  • 107
  • 4
  • This does not address DHCP – Shōgun8 Apr 05 '22 at 19:43
  • It works by removing the IP address assigned from DHCP client. – scegg May 05 '22 at 02:11
  • So it will still broadcast for a dhcp address, and when it gets one it will overwrite what you have manually entered. Do this: run tcpdump on that interface and watch what it does after you do that. – Shōgun8 May 05 '22 at 20:39
  • Yes you are right. As I said, it is only a walkaround by removing the effect, not disable the DHCP client. Several years ago, I wrote some Layer 2 network binding program which required a working interface but any IP assigned on it may break the routing on the computer. Everytime when the computer connect to a network which is for binding, it may get an ip assigned form the dhcp server of this network, and I have to remove it. Sadly, the disabling of dhcp client is not in the config of any interface but in dhcp itself. Unless the interface name and the dhcp service name is sure, nothing can do – scegg May 06 '22 at 01:19
  • A workaround is unnecessary when the issue can be addressed directly by changing the `BOOTPROTO` line in the network scripts file. – Shōgun8 May 06 '22 at 15:23
  • Yes, when you have one. – scegg May 13 '22 at 08:00