Disable DHCP

Would anyone know how to use nmcli to disable dhcp on RHEL7?
Is that even possible? If not, how can switch a network interface using dhcp to have a static IP adress?

  • post-author-pic
    Bob S

    To set a static IP address use:

     'nmcli connection add type ethernet con-name connection-name ifname interface-name ip4 address gw4 address

    EX: nmcli con add type ethernet con-name test-lab ifname ens9 ip4 gw4

    To set the DNS address use:

    EX: nmcli con mod test-lab ipv4.dns ""

  • post-author-pic
    Tariq A

    Could you use the nmcli con-mod eth0 ipv4.manual disable or manual to setup the static and disable dhcp command?

    Redhat says only via the interactive editor.idk

  • post-author-pic
    Jake W

    In addition to Bob's answer, you can also directly edit the interface script at /etc/sysconfig/network-scripts/ -- Just make sure you know what you're doing if you modify it this way. You'll need to know, for instance, that IPADDR=[address] is the way you assign the IP within the file itself, in addition to other necessary values like the default gateway that correspond to those in the nmcli command Bob wrote out. You would set the BOOTPROTO= line to 'static'

  • post-author-pic

    I would create a new connection:

    # nmcli con add con-name eth0-static  ifname eth0 type ethernet autoconnect yes ip4 gw4

    Modify to add DNS... and use the ipv4.method manual to ensure static connection:

    # nmcli con mod eth0-static  ipv4.method manual ipv4.dns

    # nmcli con up eth0-static up

    You could also try to modify the existing dhcp connection to use the manual method, but I have not verified this:

    # nmcli con mod eth0-orig connection.autoconnect yes ipv4.method manual ipv4.addresses ipv4.dns

    # nmcli con up eth0-orig

    However, I found that deleting the original dhcp connection and creating a new one works best.

    # nmcli con del eth0-orig

    Verify your work by checking the following files:

    The connection names and IP addresses used are just examples. Substitute what is applicable in your case. Hope this helps...

Looking For Team Training?

Learn More