To disable DHCP in Linux, you need to edit the network configuration file for your interface. The location and format of this file may vary depending on your Linux distribution and network manager. For example, in Ubuntu, the file is located at
/etc/netplan/01-network-manager-all.yaml
and uses YAML syntax. In CentOS, the file is located at
/etc/sysconfig/network-scripts/ifcfg-<interface>
and uses key-value pairs. You can use any text editor to edit the file, but you may need sudo privileges to do so. In the file, look for the line that says
, respectively. Then, add the following lines with the IP address, subnet mask, gateway, and DNS servers that you noted down earlier:
addresses: [<IP address>/<subnet mask>]
gateway4: <gateway>
nameservers:
addresses: [<DNS server 1>, <DNS server 2>]
IPADDR=<IP address>
NETMASK=<subnet mask>
GATEWAY=<gateway>
DNS1=<DNS server 1>
DNS2=<DNS server 2>
Save the file and exit the editor. Then, apply the changes by restarting the network service or rebooting your system. You have successfully disabled DHCP on your NIC in Linux.