Bootstrap FreeKB - Networking - IP address subnet mask and default gateway in Linux (ifcfg cidr)
Networking - IP address subnet mask and default gateway in Linux (ifcfg cidr)

Updated:   |  Networking articles

The ip address or ifconfig commands can be used to determine the name of your network interface card (NIC). In this example, the name of the NIC is eno16777728. 

~]# ip address
. . .
2: eno1677984: <BROADCAST,MULTICAST,UP,LOWER_UP) mtu 1500 qdisc pfifo_fast state UP qlen 1000
. . .
~]# ifconfig
eno16777984    Link encap:Ethernet  HWaddr 61:f3:b2:7b:21:1c
. . .

 

If using a Red Hat distribution (CentOS, Fedora, Red Hat) running Red Hat version 7 or below, edit the /etc/sysconfig/network-scripts/ifcfg-xxxxxxxx file. Replace xxxxxxxx with the name of your NIC (for example: /etc/sysconfig/network-scripts/ifcfg-eno16777728).

BOOTPROTO=x
# Replace x with dhcp, bootp, or none. 
# If set to "none", you must include IPADDR=x.x.x.x, PREFIX=/xx, and GATEWAY=x.x.x.x

DEFROUTE=x
# Replace x with "yes" or "no".
# If set to yes, the interface will be the default route.
# If set to no, the interface will not be the default route.

DEVICE=x
# Replace x with the name of your NIC.

DNS1=x
# Replace x with the IPv4 or IPv6 address of your preferred DNS server

DNS2=x
# Replace x with the IPv4 or IPv6 address of your secondary DNS server

DOMAIN=x
# Replace x with your domain name

GATEWAY=x
# Replace x with your static IPv4 default gateway address.
# If you use GATEWAY, you must also include BOOTPROTO=none, IPADDR=x.x.x.x, and NETMASK=x or PREFIX=/xx.

IPADDR=x
# Replace x with your static IPv4 address.
# If you use IPADDR, you must include BOOTPROTO=none, NETMASK=x or PREFIX=/xx, and GATEWAY=x.x.x.x.

IPV4_FAILURE_FATAL=x
# Replace x with "yes" or "no".
# If set to yes, and there is an IPv4 misconfiguration, the NIC will be disabled.
# If set to no, and there is an IPv4 misconfiguration, the NIC will not be disabled.

IPV6_FAILURE_FATAL=x
# Replace x with "yes" or "no".
# If set to yes, and there is an IPv6 misconfiguration, the NIC will be disabled.
# If set to no, and there is an IPv6 misconfiguration, the NIC will not be disabled.

IPV6ADDR=x
# Replace x with your static IPv6 address.
# If you use IPV6ADDR, you must also include BOOTPROTO=none, IPV6INIT=yes, and IPV6_DEFAULTGW=x.

IPV6INIT=x
# Replace x with "yes" or "no".
# Enable IPv6 on the interface.

IPV6_AUTOCONF=x
# Replace x with "yes" or "no".
# Set to no to disable neighborhood discovery, or yes to enable neighborhood discovery. 
# Typically, no is used if IPV6ADDR=xxxxx is set.

IPV6_DEFAULTGW=x
# Replace x with your static IPv6 default gateway address.
# If you use IPV6_DEFAULTGW, you must also include BOOTPROTO=none, IPV6INIT=yes, and IPV6ADDR=x.

IPV6_DEFROUTE=x
# Replace x with "yes" or "no".
# If set to yes, the interface will be the default route.
# If set to no, the interface will not be the default route.

IPV6_PEERDNS=x
# Replace x with "yes" or "no".
# This is typically set to yes if DNS1=x and/or DNS2=x are set.
# When PEERDNS is set to yes, the /etc/resolv.conf file will be updated to contain the IPv6 address of DNS1 and/or DNS2.
# When PEERDNS is set to no, the /etc/resolv.conf file will not be updated to contain the IPv6 address of DNS1 and/or DNS2.

NAME=x
# Replace x with the name of your NIC.

NETMASK=x
# Replace x with your subnet mask.
# PREFIX can be used instead of NETMASK.
# If you use NETMASK, you must include BOOTPROTO=none, IPADDR=x.x.x.x, and GATEWAY=x.x.x.x.

ONBOOT=x
# Replace x with "yes" or "no".
# ONBOOT is typically always yes, which tells the operating system to use this NIC during boot.
# If set to no, the NIC will not be automatically enabled, and you would have to manually enable the NIC.

PEERDNS=x
# Replace x with "yes" or "no".
# This is typically set to yes if DNS1=x.x.x.x and/or DNS2=x.x.x.x are set.
# When PEERDNS is set to yes, the /etc/resolv.conf file will be updated to contain the IPv4 address of DNS1 and/or DNS2.
# When PEERDNS is set to no, the /etc/resolv.conf file will not be updated to contain the IP4v address of DNS1 and/or DNS2.

PREFIX=x
# Replace x with your subnet mask in CIDR format.
# NETMASK can be used instead of PREFIX.
# If you use PREFIX, you must include BOOTPROTO=none, IPADDR=x.x.x.x, and GATEWAY=x.x.x.x.

 

If using a Debian distibution, such as Ubuntu or Mint, edit the /etc/network/interfaces file.

auto x
# Replace x with the interface name, such as lo, eth0, wlan0
# Brings the interface up during boot
# auto must be set in order to use ifup and ifdown

dns-nameservers
# IP address of the DNS servers

iface x inet y
# Replace x with the interface name, such as lo, eth0, wlan0
# Replace x with "dhcp" or "static"
# If "static" is used, address, netmask, and gateway must also be set

search your.domain.com
# Replace your.domain.com with your domain name

 

The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to start and enable network.

systemctl restart network
systemctl status network

 

If your system is using init, use the service command to start and enable network.

service network restart
service network status

 

Use the ip addr or ifconfig command to verify that the system has the correct configuration. 

Use the nslookup command to verify that DNS is working.

nslookup www.example.com

 

Use the route command to verify the Default Gateway has been set.

route

 

If the OS does not inherit these new settings, ensure the NetworkManager service is active and running.

systemctl status NetworkManager
service NetworkManager status 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5ce0c4 in the box below so that we can be sure you are a human.