How to Configure CentOS 7 Network Settings – Serverlab
The following tutorial will guide you through configuring CentOS 7 network settings. If you are familiar with CentOS 6 or lower, you will notice that the network configuration files are largely the same.
The biggest difference between the latest major version and those below it is the naming convention for network interfaces. Prior to CentOS 7 the network interfaces were numbered, starting from 0. The first interface would also be named eth0. This is no longer the case, as the first network interface is now labeled enp3s0. To add some confusion, the next interface is labeled enp8s0.
Mục Lục
Understanding Network Interface Naming
A predictable way of determining a network interfaces name was introduced in CentOS 6. However, it wasn’t until CentOS 7 was released that the feature was enabled by default.
The predictable naming convention assigns a name to an interface based on a number of factors. For an ethernet card, the following are used: type, bus, and slot. For example, the first network interface for a CentOS 7 server running on Virtualbox would be labeled enp3sp, or Ethernet device, bus 3, slot 0.
Device Type
en
ethernet
sl
Serial line IP (slip)
wl
wlan
ww
swan
Disabling Predictable Naming
While it is not recommended to disable this feature, you may disable it at any time. By doing so you return to having a naming convention of etc[0,1,2,3…].
Common Settings
GATEWAY: The IP address of your network gateway. Required if you require connectivity beyond your local network subnet, such as having Internet connectivity.
IPADDR: The IP address of the network interface.
Configuration File
Configuring a Static IP
A static address is one that is permanently assigned to one host. It is an address that is manually configured by the administrator.
- Open the configuration file for your network interface.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
- Add the following settings to the file:
DEVICE=enp3s0 ONBOOT=yes IPADDR=192.168.1.10 NETMASK=255.255.255.0 GATEWAY=192.168.1.1
- Save your changes and exit
- Your new settings will not apply until the network interface is restarted or brought online. If you are remotely logged into the server and modifying the network settings of the interface you are connected to, reboot the system.
- Restarting the network interface.
ifdown enp0s3
ifup enp0s3
Configuring DHCP Settings
A dynamic address is one leased from a DHCP server when a system boots or a network interface comes online. The following settings configure a network interface for DHCP.
- Open the configuration file for your network interface.
vi /etc/sysconfig/network-scripts/ifcfg-
- Add the following settings. If a configuration already exists, modify it to look like the following:
DEVICE=enp3s0 ONBOOT=yes DHCP=yes
- Save your changes and exit
- Your new settings will not apply until the network interface is restarted or brought online. If you are remotely logged into the server and modifying the network settings of the interface you are connected to, reboot the system.
- Restarting the network interface.
ifdown enp0s3
ifup enp0s3
Validate Your Network Settings
You will want to ensure that your network interface has applied your new settings. You can use the IP command to output its settings.
ip a show enps3s0
The output will display basic information about the interface, such as device name, IP address, MAC address, etc. The following is an example of the output.
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:b2:73:09 brd ff:ff:ff:ff:ff:ff inet 192.168.1.218/24 brd 192.168.1.255 scope global dynamic enp0s3 valid_lft 604708sec preferred_lft 604708sec inet6 fe80::340f:7dd6:76fc:780b/64 scope link tentative dadfailed valid_lft forever preferred_lft forever inet6 fe80::18f3:7b5:6d27:2b78/64 scope link tentative dadfailed valid_lft forever preferred_lft forever inet6 fe80::303d:1226:78e0:763e/64 scope link tentative dadfailed valid_lft forever preferred_lft forever
No related posts found