How to disable DHCP (static IP)?

33,264

Solution 1

This heavily depends on whether or not your router supports it.

You do not need to disable DHCP, the DHCP reservations will need to be provided by your router and the router should have to set up a static standing reservation of the MAC address of the network interface to an IP address.

Of course you don't have to and you can disable DHCP and set up a static IP address altogether on the system by editing /etc/rc.inet1.conf. You can look at the documentation on possible settings here

Solution 2

  • To disable Disable DHCP on my openSUSE machine I use the following script. The main thing to note is that, unlike "service SERVICENAME stop" command, "systemctl disable SERVICENAME.service" persists after boot (where SERVICENAME is the name of the service you want to disable).

    systemctl disable wickedd-dhcp4.service

wickedd-dhcp4 was the name of service handling DHCP client configuration on my system. For disabling IPv6 DHCP as well use the following.

systemctl disable wickedd-dhcp6.service


  • Once you have the DHCP disabled, you can assign static IP by either of the following ways.

    1. Editing "/etc/network/interfaces" file one sample configuration to assign static IP to eth0 interface could be the following.

    allow-hotplug eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1
    dns-nameservers 8.8.8.8

    1. using ifconfig (Ubuntu)

    ifconfig eth0 192.168.1.100 netmask 255.255.255.0

    1. Using ip command (openSUSE)

    ip addr add 192.168.1.100/24 brd + dev eth0

Needless to say that there are hundreds of other commandling utilities available.

Share:
33,264

Related videos on Youtube

Zeno
Author by

Zeno

Updated on September 18, 2022

Comments

  • Zeno
    Zeno almost 2 years

    If I want to set my Slackware machine to have a static IP assigned from the router, how can I do so?

    I assume I have to disable DHCP then edit something to set the requested IP, but I'm not sure where.

    (I don't have a GUI)

    • llua
      llua over 12 years
      Could you be a little bit more clear? are you trying to set a static IP address(assigned by the node) or DHCP Reservation(which is does by the DHCP service)? your question suggests DHCP Reservation, but your "idea" suggest you are setting a static IP.
    • Zeno
      Zeno over 12 years
      I'm trying to set a static local IP on the Linux machine, like Windows can do.
  • Zeno
    Zeno over 12 years
    I have a static local IP on a Windows7 machine under the route, I assume it's supported. This is done by doing a setting on the Win7 machine and not the router though.
  • Shadur
    Shadur over 12 years
    @Zeno Yeah, that's one way to do it. The wrong way -- it technically works, but only because there aren't any other systems on your LAN and you're not generating collisions. Telling your router to assign a specific, static IP to the MAC address of your computer is the right way to do it.
  • Karlson
    Karlson over 12 years
    @Shadur If Win7 is a DHCP Server that's the only way to do it and even if it's not it's not wrong if you configure DHCP ranges correctly.
  • Karlson
    Karlson over 12 years
    @Zeno Take a look at the last paragraph of my answer and the link.
  • Shadur
    Shadur over 12 years
    @Karlson What I think he means is that he's got one router and one actual desktop comp that dualboots windows and linux, and in windows he just assigns a static IP.
  • Karlson
    Karlson over 12 years
    @Shadur In that case he would have had GUI available.
  • Zeno
    Zeno over 12 years
    Sorry, I have 2 computers on the network; one Windows and one Linux. I want both to have a static IP on the network.
  • Karlson
    Karlson over 12 years
    @Zeno You'll need to edit /etc/rc.inet1.conf to provide the system with a static IP address.
  • Zeno
    Zeno over 12 years
    That file doesn't exist for me, is that normal? EDIT: I found it under /etc/rc.d/rc.inet1.conf