Using network utilities traceroute, dig in CentOS

Dynamic Host Configuration Protocol is a network protocol used to dynamically distribute network configuration parameters, such as IP addresses, gateway, and DNS for network interfaces. DHCP Server assigns IP addresses automatically to all systems, so system admin need not assign IP addresses manually to client machines in the network. DHCP is the best option for bigger environments, holds thousands of systems.

Environment

Make sure to have only one DHCP server in your environment. If you have a router/switch which provides the functionality of DHCP, then you need to disable it.

  1. CentOS 7 64bit Minimal server (DHCP Server) OR Ubuntu 18.04 /16.04 / Debian 9 64bit (DHCP Server)
  2. CentOS 7 64bit Minimal server (DHCP Client) OR Ubuntu 18.04 / 16.04 Desktop (DHCP Client)

Note: You must a assign a static IP address to your DHCP server.

Install and configure DHCP server on CentOS 7

First, let us see how to install and configure DHCP server on CentOS 7 64bit. The should also work on CentOS 6.x and other older versions.

# yum install dhcp

Once the packages are installed, copy the sample configuration file to /etc/dhcp directory.

# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

Now, edit dhcpd.conf file.

# vi /etc/dhcp/dhcpd.conf

[...] # Specify Domain Name#DefaultGateway

192.168.12.110

# systemctl restart dhcpd # systemctl enable dhcpd

If you face any issues in restarting the DHCP service, then consider updating the SELinux context or .

/sbin/restorecon -v /etc/dhcp/dhcpd.conf

That's it. Now, skip to ‘ ’ section and configure your clients to get IP addresses automatically from the DHCP server.

Install and configure DHCP server on Ubuntu 18.04 / 16.04 / Debian 9

First, let us see how to install and configure DHCP server on Ubuntu 14.04. The should also work on Ubuntu 15.04 / 14.10 / 13.04 / 13.10 and other older versions.

Install DHCP server and client using the below command.

$ sudo apt-get install isc-dhcp-server

Once the packages are installed, we have to assign on what interfaces should the DHCP server ( dhcpd) serve DHCP requests. In our case, have only one Interface on my system ( eth0), so we will assign eth0.

Edit file /etc/default/isc-dhcp-server.

$ sudo nano /etc/default/isc-dhcp-server

Mention eth0 in the file.

# Separate multiple interfaces with spaces, e.g. "eth0 eth1". INTERFACES="eth0"

Now, edit dhcpd.conf file,

$ sudo nano /etc/dhcp/dhcpd.conf

Do the changes as shown below.

Define the subnet, range of IP addresses, domain and domain name servers as below:

[...] # Configuring subnet and iprange subnet 192.168.12.0 netmask 255.255.255.0 ( range 192.168.12.100 192.168.12.200; # Specify DNS server ip and additional DNS server ip option domain-name-servers 8.8.8.8, 8.8.4.4; # Specify Domain Name option domain-name "itzgeek.local"; #DefaultGateway option routers 192.168.12.2; option broadcast-address 192.168.12.255; # Specify Default and Max lease time

default-lease-time 600; 192.168.12.110 max-lease-time 7200;

) [...]

If you want to assign a fixed IP address to your client, you have to enter it’s MAC id and the IP address in the following stanza. For example, to assign a fixed IP address

to the client, stanza will look like below.

[...] host mywindows-client ( hardware ethernet 00:0C:29:05:A7:CB; fixed-address 192.168.12.110; ) [...]

Now, start the dhcpd service and make it start automatically on system reboot. # sudo service isc-dhcp-server restart Configure DHCP Clients

Now, you need to configure client machines to get IP address automatically from DHCP server.

You can go through below articles. Network setup in CentOS 7

Which is described in the corresponding article, you need to perform a number of basic settings. One of which is setting network connections. Let's consider this operation in order. For novice users Linux Difficulties may arise at the very first stage - it will not be possible to check the current state of the network with the command ifconfig

(a message will be displayed - command not found). This is not a problem, this is a feature of how CentOS works, so this command must be run as superuser (administrator) with the command: The reason is that normal system users and root user have different environment variables PATH (you can view the user's PATH using echo $PATH). After entering Linux commands , the shell will search the user's PATH to try to find a command to run. It starts searching every directory listed in PATH until the target is found. Teams are located mainly in /usr/local/sbin, /usr/sbin, /sbin and the root PATH reflects this. So when you become superuser with "su -", you also take on a new PATH for your main commands. And using only 'su', the default user PATH is preserved, therefore, when trying to execute a program located in /usr/local/sbin, /usr/sbin, /sbin it will produce the result: 'command not found’ error. For a more detailed explanation, see the man bash page, especially the login shells section. So you or should indicate full path to the command (example - /sbin/ifconfig) when using 'su', or use 'su -' when becoming root.

To check the current network settings, use the command:

When working in the Linux OS family, you need to know and understand that all hardware and software devices, as well as various parameters of the operating system and programs are stored in configuration files. Thus, interface configuration files control software interfaces individual network devices. When the OS boots, these files and information in it are read, on the basis of which the necessary (used and configured) interfaces are determined, as well as their launch.

Such files are usually called ifcfg-<имя> , Where<имя>refers to the name of the device that is controlled by this configuration file. As mentioned above, all interfaces and OS parameters are stored in various specialized files, which gives the administrator a convenient and flexible ability to configure OS and hardware parameters.

Setting up the network interface

Let's configure the network interface by editing the configuration file, which is located in the /etc/sysconfig/network-scripts/ directory

In my case, the cable is connected to the first (and only) network adapter, which is called in the system eth0. Let's edit the corresponding file:

# vi /etc/sysconfig/network-scripts/ ifcfg-eth0

I remind you to make changes to the contents of the file in the editor vi- necessary:

  • press the “i” or “Insert” key
  • to exit editing mode - “esc”
  • to save the changes - “Shift+:” then “wq” and press “Enter”

For a network with a static IP address:

DEVICE=”eth0″
BOOTPROTO="none"
ONBOOT=”yes”
IPADDR="192.168.1.100″
NETMASK=”255.255.255.0″
GATEWAY=”192.168.1.1″

For a network using DHCP:

DEVICE=”eth0″
BOOTPROTO="dhcp"
ONBOOT=”yes”

Comments on the actions performed:

Network setup

We edit the network configuration file:

# vi /etc/sysconfig/network

Enter the following data:

NETWORKING=”yes”
HOSTNAME=”Name.of.Your.Server” or workstation

To apply the settings correctly (so that they take effect), restart the network:

# /etc/init.d/network restart

If changes to the /etc/sysconfig/network file are not required, then only the interface can be restarted:

# ifdown eth0 && ifup eth0

It's also worth knowing that Network setup can be done faster, execute these commands:

ifconfig eth0 192.168.Х.Х netmask 255.255.255.0

To disable the network interface:

If you want the settings to be received automatically via DHCP, then run the following command:

In this case, to stop the network interface, you will need to shut down the dhclient program:

BUT!When setting up a network in this way, after a reboot the configuration will have to be done again.

DNS Settings

Open the file ‘resolv.conf’:

In this material I will touch on a current topic with which almost any initial work with the server begins. Configuring basic network parameters in CentOS 7 and 8 - ip address, dhcp, ipv6, dns, hostname, static routes, network cards and other network parameters. We will move on the topic step by step from simple to complex, analyzing all the nuances in order and answering the most popular questions.

  1. Tell me how to do the basics network settings on a centos server versions 7 and 8.
  2. Show additional network configuration options.
  3. Use a few examples to explain how to solve typical problems with the network.
  4. Show some useful network utilities.

This article is part of a single series of articles about the server.

Network settings on a CentOS server

The first time we encounter the network settings of a CentOS 7 or 8 server is when we perform the installation. On the screen initial setup There is a separate point regarding setting up network interfaces:

Having entered it, we see a list of connected network cards. Each of them can be turned on using the corresponding slider (point 1 in the picture). When the interface is activated, it automatically receives settings via dhcp. You can see the result of dhcp work right there. If you are not happy with these settings, you can edit them by clicking configure(point 3 in the picture). Here you can also set hostname(point 2 in the picture):


Opening the window additional settings Ehernet, you can change the name of the network interface, specify the IP settings (item 1 in the picture), select manual settings (point 2 in the picture), assign ip address(point 3 in the picture), install dns server(point 4 in the picture) and save the network settings (point 5 in the picture):


After completing the remaining settings, the installation will begin. After installation, you will have a server with the network settings you specified.

Now let's consider another situation. You did not create the server, and therefore the network configuration, but now you need to look at it or change it. The server console is at your disposal, and we will work in it. If you installed from a distribution kit minimal, then when you try to view the network settings using the command For novice users in the console you will see the following:

Bash: ifconfig: command not found

or in Russian version:

Bash: ifconfig command not found

To work with ifconfig and other network utilities you need to install the package net-tools. Let's do it:

# yum install net-tools

Now you can see the network settings:

mtu 1500 inet 192.168.159.129 ether 00:0c:29:7d:59:3f txqueuelen 1000 (Ethernet) RX packets 319 bytes 36709 (35.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 256 bytes 148817 (145.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6::1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Local Loopback) RX packets 6 bytes 624 (624.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 624 (624.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

If you do not want to install an additional package, you can use a simpler command ip with parameters:

# ip addr 1: lo: mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6::1/ 128 scope host valid_lft forever preferred_lft forever 2: eno16777728: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:7d:59:3f brd ff:ff:ff:ff:ff:ff inet 192.168.159.129 /24 brd 192.168.159.255 scope global dynamic eno16777728 valid_lft 1709sec preferred_lft 1709sec inet6 fe80::20c:29ff:fe7d:593f/64 scope link valid_lft forever preferred_lft forever

We have seen the network configuration, now let's edit it. Let's say we need to change the IP address. To do this, go to the directory and open the file for editing ifcfg-eth0 or ifcfg-ens18. The file name will depend on the name of the network interface. By default, Centos 8 removed support for setting up a network through configuration scripts, so install the network-scripts package separately.

# yum install network-scripts

The ifcfg-eth0 file has approximately the following content:

Using the settings from this file, we get the IP address via dhcp. To manually register a static IP, we bring the file to the following content:

We have changed the parameters:

For the changes to take effect, you need to re-read the network settings:

Check if the new network configuration has been applied:

# ifconfig eth0: flags=4163 mtu 1500 inet 192.168.159.129 netmask 255.255.255.0 broadcast 192.168.159.255 inet6 fe80::20c:29ff:fe7d:593f prefixlen 64 scopeid 0x20 ether 00:0c:29:7d:59:3f txqueuelen 1000 (Ethernet) RX packets 672 bytes 71841 (70.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 572 bytes 290861 (284.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Everything is fine, the new network interface settings are installed.

How to get network settings via DHCP

Now let's consider the opposite situation. Let's say you have LAN card has some settings set manually. But you want your computer to receive network settings via dhcp as a client. To do this, you need to perform the opposite operation to what we did before. That is, we open the file /etc/sysconfig/network-scripts/ifcfg-ens18 and delete there the lines with the parameters DNS, IPADDR, PREFIX, GATEWAY and in the BOOTPROTO parameter we indicate the value "dhcp".

Save the file and restart the network:

# systemctl restart network

Then we check whether our client has received the settings via dhcp.

How to configure DNS on CentOS

The current dns server settings in CentOS can be viewed in two places:

  1. In the file with the settings of the network card ifcfg-eth0, which we have previously edited several times.
  2. In the /etc/resolv.conf file

Why they are now in two places, I don’t know, but before, the DNS server settings in some distributions, I don’t remember exactly which ones, were indicated only in resolv.conf, but at some point this changed. And all network settings began to be stored in one file along with the address, gateway, mask, and so on. If you now edit the resolv.conf file and add some server dns there, then after a reboot they will be replaced with the values ​​​​from the ifcfg-eth0 file.

So in order to set the DNS server parameters, you need to edit the ifcfg-eth0 network settings file, adding as many servers as required. For example like this:

DNS1="192.168.159.2" DNS2="8.8.8.8" DNS3="8.8.4.4"

To apply the settings, save the file and restart the network, everything is as usual. After rebooting the server, the dns settings will be written to the resolv.conf file

# cat /etc/resolv.conf # Generated by NetworkManager nameserver 192.168.159.2 nameserver 8.8.8.8 nameserver 8.8.4.4

How to disable ipv6

Currently in active use of the protocol ipv6 in Russia it is not and in normal work it is most often not needed. Although we have been scared for many years that there are practically no free IP addresses left, in reality there are still enough for everyone. So for practical reasons, ipv6 is not currently needed on the server and can be disabled.

Before disabling ipv6 in centos, just in case, you need to check which programs use it in their work. This is necessary in order to avoid errors in their operation by first disabling ipv6 in the configurations. In order to see what programs are hanging on the ipv6 interface, use the netstat command:

# netstat -tulnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2317/master tcp 0 0 0.0.0.0 :22 0.0.0.0:* LISTEN 1333/sshd tcp6 0 0::1:25:::* LISTEN 2317/master tcp6 0 0:::22:::* LISTEN 1333/sshd udp 0 0 0.0.0.0:49252 0.0.0.0:* 694/avahi-daemon: r udp 0 0 0.0.0.0:123 0.0.0.0:* 715/chronyd udp 0 0 0.0.0.0:5353 0.0.0.0:* 694/avahi-daemon: r udp 0 0 127.0.0.1:323 0.0.0.0:* 715/chronyd udp6 0 0:::123:::* 715/chronyd udp6 0 0::1:323:::* 715/chronyd

All lines with ::: are ipv6 protocol. In my case it is sshd, postfix and chronyd. Let's disable ipv6 for them and leave only ipv4.

Let's start with sshd. Open the settings file /etc/ssh/sshd_config and find the lines:

#AddressFamily any #ListenAddress 0.0.0.0

Let's uncomment them and change them. It should look like this:

AddressFamily inet ListenAddress 0.0.0.0

Now open the postfix settings file /etc/postfix/main.cf. We are looking for the line there:

#inet_protocols = all

Change to:

Inet_protocols = ipv4

Disable ipv6 in chronyd. To do this, create a file /etc/sysconfig/ chronyd and add the line:

OPTIONS=-4

Now we disable ipv6 in CentOS. Open the file /etc/ sysctl.conf and add the lines there:

Net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1

Editing the file /etc/sysconfig/ network , adding there:

NETWORKING_IPV6=no IPV6INIT=no

Add a ban on ipv6 to the grub configuration. Open the config /etc/default/grub and add another value to the GRUB_CMDLINE_LINUX parameter ipv6.disable=1. It should look something like this:

GRUB_CMDLINE_LINUX="rd.lvm.lv=cl_centos8/root rhgb quiet ipv6.disable=1"

After this, we update the bootloader config.

# grub2-mkconfig -o /boot/grub2/grub.cfg

Reboot and check the result:

# reboot # ifconfig eno16777728: flags=4163 mtu 1500 inet 192.168.159.129 netmask 255.255.255.0 broadcast 192.168.159.255 ether 00:0c:29:7d:59:3f txqueuelen 1000 (Ethernet) RX packets 2301 bytes 243024 (237.3 KiB) errors 0 dropped 0 overruns 0 frame 0 TX packets 2138 bytes 1327955 (1.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 0 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

There is no mention of inet6 and ipv6 format addresses anywhere. So everything is fine, we have disabled ipv6 in CentOS. Now let's check the list of open ports:

# netstat -tulnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2291/master tcp 0 0 0.0.0.0 :22 0.0.0.0:* LISTEN 1322/sshd udp 0 0 0.0.0.0:123 0.0.0.0:* 2453/chronyd udp 0 0 0.0.0.0:5353 0.0.0.0:* 697/avahi-daemon: r udp 0 0 127.0.0.1:323 0.0.0.0:* 2453/chronyd udp 0 0 0.0.0.0:57259 0.0.0.0:* 697/avahi-daemon: r

All ports are ipv4. Everything is in order, our task is completed.

How to change hostname on CentOS

By default, during CentOS installations puts the hostname localhost.localdomain. If you haven't changed it, you can do it later. First, let's check what hostname you have set. This is done using the command in the console hostname, or using uname:

# hostname localhost.localdomain # uname -n localhost.localdomain

In order to change the hostname in CentOS, you need to edit the file /etc/hostname. Let's check its contents:

# cat /etc/hostname localhost.localdomain

Let's edit this file to change the hostname:

# mcedit /etc/hostname centos.localhost

Save the file and check:

# hostname centos.localhost

There is a ready-made command that immediately sets the required server name:

# hostnamectl set-hostname centos.localhost

Everything is ok, we changed the hostname to centos.localhost

Set the default gateway in CentOS

If for some reason you did not set the default gateway when setting up network parameters, you can do this manually. First, let's check which default gateway is installed in the system in this moment:

# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 149.154.71.254 0.0.0.0 UG 0 0 0 eth0 0.0.0 0 0 0 eth0 192.168.1.0 10.8.0.2 255.255. 255.0 UG 0 0 0 tun0

The line with Destination 0.0.0.0 specifies the gateway address. If you don’t have it, or the wrong gateway is set in the Gateway field, you can change this. Set the default gateway:

# route add default gw 192.168.0.1

Or the same with the ip command.

# ip r default via 10.20.1.1 dev ens18 proto dhcp metric 100 10.20.1.0/24 dev ens18 proto kernel scope link src 10.20.1.23 metric 100 # ip route add default 10.20.1.0/24 dev ens18

# ip route add default via 10.20.1.1

Network Manager on CentOS

CentOS by default has a service that manages all network connections - NetworkManager. It constantly monitors network settings and, using a configuration management daemon, makes appropriate changes to active network devices. It supports standard ifcfg configuration files.

List of network utilities and applications:

Users do not interact with NetworkManager on CentOS directly; they use graphical and command line utilities to do so. One such utility is system config network tui. In Centos 8, by default, NetworkManager is the recommended method for setting up a network. All other methods are declared deprecated.

System config network tui

To manage network settings in CentOS, you can use a graphical utility nmtui. It is very easy to check its presence in the system. Just run it in the console:

If you don't have it installed, it's very easy to fix. Install in CentOS system config network tui:

# yum install NetworkManager-tui

By using tui you can specify any network settings that we did before via command line and editing network-scripts configuration files. Let's do that. Call the program:

Select the first item Edit a connection, then select the network interface and click “Edit”:

Here we can change the name of the network card, mac address, specify the type of network settings - manual or dhcp, manually specify the IP address, gateway address, DNS server, add routes and some other settings:

After editing is complete, save the settings by clicking OK.
If you select the item on the first screen of the utility Set System Hostname, you can quickly specify the hostname. The result will be the same as we did before in the console.

If you are preparing to take the RHEL certification, you will see everywhere a recommendation to use nmtui to configure the network. The bottom line is that time is limited during the exam, and with the help of a network manager you can and should save it. It is believed that setting up a network this way is faster.

How to add a static route on CentOS

To control routing on CentOS, you may need to add a static route. This can be done quite simply using console command. First, let's check the existing routes using netstat:

# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.159.2 0.0.0.0 UG 0 0 0 eno16777728 192.168.159.0 0.0.0.0 255.255.255.0 U 0 0 eno16777728

In this case, we have one route for the address 0.0.0.0/0.0.0.0; the gateway is 192.168.159.2, which is also the default gateway. That is, in essence, there are no static routes. Let's add one of them.

Let's say we have a subnet 192.168.8.0 mask 255.255.255.0, traffic to this subnet is routed by the gateway 192.168.159.5 Add a route:

# route add -net 192.168.8.0/24 gw 192.168.159.5

We check whether the added route has appeared in routing table:

# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.159.2 0.0.0.0 UG 0 0 0 eno16777728 192.168.8.0 192.168.159.5 255.255.255.0 U G 0 0 0 eno16777728 192.168.159.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777728

Everything is ok, the route has been added. We do the same using the ip utility.

# ip r # ip route add 192.168.8.0/24 via 192.168.159.5

But after reboot this static route will be deleted. To prevent this from happening and to save the added routes, you need to write them to a special file. In folder /etc/sysconfig/network-scripts create a file named route-eth0 the following content:

# mcedit /etc/sysconfig/network-scripts/route-eth0 192.168.8.0/24 via 192.168.159.5

Reboot and check if the route is in place:

# reboot # netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.159.2 0.0.0.0 UG 0 0 0 eno16777728 192.168.8.0 192.168.159.5 255.255.25 5.0 UG 0 0 0 eno16777728 192.168.159.0 0.0 .0.0 255.255.255.0 U 0 0 0 eno16777728

Everything is fine, the static route has been added.

How to configure 2 IP addresses on one interface

If you need to configure 2 IP addresses on one interface in CentOS, then doing this is quite simple. Let's use the ifconfig command. First, let's check the list of network interfaces:

# ifconfig eno16777728: flags=4163 mtu 1500 inet 192.168.159.129 netmask 255.255.255.0 broadcast 192.168.159.255 ether 00:0c:29:7d:59:3f txqueuelen 1000 (Ethernet) RX packets 254 bytes 30173 (29.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 204 bytes 27658 (27.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73

Let's add another IP address 192.168.159.120 to the eno16777728 interface:

# ifconfig eno16777728:1 192.168.159.120 up

Let's check what happened:

# ifconfig eno16777728: flags=4163 mtu 1500 inet 192.168.159.129 netmask 255.255.255.0 broadcast 192.168.159.255 ether 00:0c:29:7d:59:3f txqueuelen 1000 (Ethernet) RX packets 254 bytes 30173 (29.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 204 bytes 27658 (27.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno16777728:1: flags=4163 mtu 1500 inet 192.168.159.120 netmask 255.255.255.0 broadcast 192.168.159.255 ether 00:0c:29:7d:59:3f txqueuelen 1000 (Ethernet) lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 0 (Local Loopback) RX packets 11 bytes 940 (940.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 11 bytes 940 (940.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

The same thing using ip.

# ip a add 192.168.159.120/24 dev eno16777728:1

Everything is fine, we added a second IP address to the same interface. But after a reboot, the additional address will not be saved. To save it, you need to create an interface settings file in the folder /etc/sysconfig/network-scripts

# mcedit /etc/sysconfig/network-scripts/ ifcfg-eno16777728:1 DEVICE=eno16777728:1 BOOTPROTO=static IPADDR=192.168.159.120 NETMASK=255.255.255.0 ONBOOT=yes

Save the file, reboot and check what happened. The second IP address must be in place.

How to do a network restart in CentOS

I have already touched on this issue earlier, but just in case, we will repeat it separately. Let's say you've made some changes to your network configuration. How can I apply these settings without rebooting the server? Very simple. To restart the network in CentOS, just use the systemd command:

# systemctl restart network

If you see an error:

Failed to restart network.service: Unit network.service not found.

This means that you do not have the network-scripts package installed, and the network is managed using NetworkManager, which itself restarts the network after changing the settings.

If you have old version Centos without systemd, and this is version 6 and younger, then the network restarts like this.

# /etc/init.d/network restart

The network service will re-read all network settings and apply the changes.

How to find out the IP address in CentOS

In order to quickly find out the current IP address in CentOS, you need to use the following commands:

# ifconfig | grep inet inet 192.168.159.129 netmask 255.255.255.0 broadcast 192.168.159.255 inet 127.0.0.1 netmask 255.0.0.0

Or the second option for determining the local IP address:

# ip addr | grep inet inet 127.0.0.1/8 scope host lo inet 192.168.159.129 /24 brd 192.168.159.255 scope global eno16777728

Both commands allow you to quickly find out your IP address.

What to do if CentOS does not see the network card?

You installed the server, booted up and discovered that there is not a single network card in the system. What to do in this case? First of all, look at the output of the dmesg command and look for a memory of your card there. Perhaps it is in the system, just not activated. You can activate it using nmtui, which I told above.

There is a menu item Activate connection, you need to go into it and activate your network card. After this you can configure it.

If your network card is not in the system, then you need to search the Internet for information about this network card by model. Perhaps there will be drivers for it in the repositories. This is a fairly common situation. Most often, drivers will be found and they will need to be installed correctly.

There is still a possibility that you will not see your card when the ifconfig command is output if the network wire is not plugged into this card. To be sure to view all interfaces, you must use the -a switch:

# ifconfig -a

There is another way to look for a network card in the system. Install the package pciutils:

# yum -y install pciutils

And look at the output of the command:

#lspci | grep Ethernet

If the network card is seen by the system, then there should be something like this:

02:00.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

If the output is empty, then the network card is not defined.

What to do if the network is not available on CentOS?

Let's say you are trying to ping some address, for example 8.8.8.8, and you receive a response that the network is not available:

#ping 8.8.8.8

And in response you get:

Connect: Network is unavailable

This situation may arise if you do not have a default gateway installed. You can add it using the command:

# route add default gw 192.168.0.1

If the problem is not with the gateway, then you need to check the settings of the network adapters. If there is no active adapter, then you will also receive a message that the network is not working. It is necessary that at least one network adapter is correctly configured on the system. How to do this is written above.

Using network utilities traceroute, dig in CentOS

To diagnose network connections in CentOS it is useful to use special utilities. But if you used the minimal installation, then most likely they will not be on the system. For example, the popular utility traceroute When you try to launch it, it will display the following message:

# traceroute ya.ru bash: traceroute: command not found

It needs to be installed separately from the repository:

# yum install traceroute

Same thing with the popular program dig to work with DNS servers and records:

# dig ya.ru bash: dig: command not found

For this network utility to work, you must install the package bind-utils:

# yum install bind-utils

Configuring 802.1Q VLAN on CentOS

To raise a tagged interface on CentOS, you first need to check kernel support 8021q:

#modprobe8021q

If there are no error messages, then everything is in order, the module has loaded. If the module is not found, you need to rebuild the kernel modules, enabling support for the required module. Let’s check, just in case, whether the module has loaded:

# lsmod | grep 8021q 8021q 29022 0 garp 14384 1 8021q mrp 18542 1 8021q

Everything is fine, the 8021q module is loaded, let's add it to startup:

# echo 8021q >> /etc/modules-load.d/8021q.conf

Now we create a configuration file for vlan in /etc/sysconfig/network-scripts:

# mcedit ifcfg-eth0.2000 VLAN=yes DEVICE=eth0.2000 BOOTPROTO=static ONBOOT=yes TYPE=Vlan IPADDR=192.168.100.2 NETMASK=255.255.255.0

I draw your attention to what is highlighted in bold. In all the instructions on the Internet that I came across, this parameter was indicated as TYPE=Ethernet, but with this setting the interface with vlan did not rise, an error appeared:

Error: no device found for connection "System eth0.2000".

Only after I fixed it did everything work as it should. So save and activate the interface:

# ifup eth0.2000 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)

Checking our vlan:

# ip l ls 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:15:5d:01:0f:06 brd ff:ff:ff:ff:ff:ff 3: eth0.2000@eth0: mtu 1500 qdisc noqueue state UP mode DEFAULT link/ether 00:15:5d:01:0f:06 brd ff:ff:ff:ff:ff:ff

Everything is fine, the tagged interface is up. By analogy, you can create several more similar interfaces, not forgetting to change their names and addresses.

Conclusion

This concludes my voluminous material on the topic of network setup in CentOS. I will be very glad to receive comments, remarks, and corrections. They probably will. By creating such materials, I first of all learn myself and improve my knowledge in the subject area. There may be errors and typos here somewhere, although I check everything on live systems when writing manuals, but inaccuracies and typos are still possible.

Let me remind you that this article is part of a single series of articles about the server.

Online course on Linux

If you have a desire to learn how to build and maintain highly available and reliable systems, I recommend that you get acquainted with online course “Linux Administrator” in OTUS. The course is not for beginners; for admission you need basic knowledge of networks and Linux installation to the virtual machine. The training lasts 5 months, after which successful course graduates will be able to undergo interviews with partners. What this course will give you:
  • Knowledge of Linux architecture.
  • Development modern methods and data analysis and processing tools.
  • Ability to select a configuration for the required tasks, manage processes and ensure system security.
  • Proficient in the basic working tools of a system administrator.
  • Understanding of the specifics of deploying, configuring and maintaining networks built on Linux.
  • The ability to quickly solve emerging problems and ensure stable and uninterrupted operation of the system.
Test yourself on the entrance test and see the program for more details.

) is a network protocol used for assigning IP address to network clients dynamically from a predefined IP pool. It is useful for LAN network, but not generally used for production servers. This article will help you for Configuring DHCP Server on CentOS, Red Hat System. Read more about dhcp.

Install DHCP Package

First install DHCP packages using yum package manager on CentOS, Red Hat systems. DHCP rpms are available under base repositories, so we don’t need to add an extra repository.

Yum install dhcp

Update /etc/sysconfig/dhcpd File

Firstly we need to set ethernet interface name as DHCPDARGS in /etc/sysconfig/dhcpd file. Edit this configuration file and update the ethernet name.

DHCPDARGS=eth1

Configure DHCP Server

DHCP creates an empty configuration file /etc/dhcp/dhcpd.conf. Also it provides a sample configuration file at /usr/share/doc/dhcp*/dhcpd.conf.sample, which is very useful for configuring the DHCP server.

So as a first part, copy the content of sample configuration file to the main configuration file. Sample configuration file may be changed as perversion you have installed on your system.

# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

3.1 – Parameter Configuration

First configure the basic options which is common to all supported networks.

Website, ns2.site;

default-lease-time 600;

max-lease-time 7200; 192.168.1.0/24 authoritative;

log-facility local7;

3.2 – IP Subnet Declaration

First, edit DHCP configuration file and update subnet details as per your network. For this example we are configuring DHCP for

LAN network.

Subnet 192.168.1.0 netmask 255.255.255.0 ( option routers 192.168.1.254; option subnet-mask 255.255.255..168.1.1; option time-offset -18000; # Eastern Standard Time range 192.168.1.10 192.168.1.100; )

3.3 -Assign Static IP Address to Host

In some cases, we need to assign a fixed IP to an interface each time it requested from dhcp. We can also assign a fixed IP based on MAC address (hardware ethernet) of that interface. Setup host-name is optional to set up.

Host station1 ( option host-name "station1.example.com"; hardware ethernet 00:11:1A:2B:3C:AB; fixed-address 192.168.1.100; )

For CentOS/RHEL 7 systemctl stop dhcp ystemctl restart dhcp For CentOS/RHEL 6/5 service dhcp stop service dhcp restart

Step 5: Setup Client System

At this stage we have a running dhcp server which is ready for accepting requests and assign them a proper ip. but to verify I have another CentOS machine running on the same LAN. Now login to that client machine and edit Ethernet configuration file.

Vim /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 BOOTPROTO=dhcp TYPE=Ethernet ONBOOT=yes

Make sure BOOTPROTO is set to dhcp.

Let's restart network services on the client machine. You will get that dhcp server assigned an ip address from the defined subnet. If you have connected to client pc from remote login, Your session can be disconnected.

For CentOS/RHEL 7 systemctl restart network For CentOS/RHEL 6/5 service network restart

In this note I want to look at a simple and quick option gateway settings for organizing Internet access from local network based on CentOS 7. There will be no additional functionality, only the essentials for computers behind the gateway to access the Internet.

This article is part of a single series of articles about the server.

Introduction

We will have the following server at our disposal to configure the gateway:

# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core)

Preliminary server setup

# yum -y update

After that I install mc, since I’m used to it and use it all the time:

# mcedit /etc/sysconfig/selinux

We reduce the line with the corresponding parameter to the following form:

SELINUX=disabled

To apply the changes, reboot the server:

# reboot # yum -y install epel-release

Install iftop on CentOS 7:

# yum -y install iftop

Now we can watch the network load on the gateway in real time. To see network activity, just run iftop:

By default, it listens to the eth0 interface. This is the external interface of the gateway, on it all connections will be displayed on behalf of the gateway itself and we will not be able to determine who on the network occupies the channel. To see this, you need to start viewing network activity on the local interface. This is not difficult to do, just run iftop with the parameter:

# iftop -i eth1 -P

In my case, this is a user with ip 192.168.10.98, on which I ran an Internet speed check from Yandex servers.

If you do not have a large network and not many users, then with the help of this simple and effective utility you can easily determine who, for example, downloads torrents or otherwise loads the channel.

Conclusion

Using a free Linux distribution, we were able to set up a gateway in a matter of minutes to provide Internet access for computers from a local network. It took me about 10 minutes to configure the gateway using these instructions. If you are doing this for the first time, then of course it will take you much longer. It will be necessary to understand the nuances, and I have given many links to additional material.

Let's look at what we did:

  1. We performed preliminary configuration of the server and prepared it for operation.
  2. Routing has been enabled.
  3. Set up the firewall.
  4. NAT enabled.
  5. Installed and configured dnsmasq for the organization dns services and dhcp.
  6. We analyzed the network activity of the gateway and found out who is loading the Internet channel.

This is the minimum required functionality for organizing the operation of the gateway on CentOS 7. The next step may be setting up a proxy server, a traffic shaper, setting up 2 or more providers, and much more. I will consider some of this in my future articles.

Let me remind you that this article is part of a single series of articles about the server.

Online course on Linux

If you have a desire to learn how to build and maintain highly available and reliable systems, I recommend that you get acquainted with online course “Linux Administrator” in OTUS. The course is not for beginners; to enroll you need basic knowledge of networks and installing Linux on a virtual machine. The training lasts 5 months, after which successful course graduates will be able to undergo interviews with partners. What this course will give you:
  • Knowledge of Linux architecture.
  • Mastering modern methods and tools for data analysis and processing.
  • Ability to select a configuration for the required tasks, manage processes and ensure system security.
  • Proficient in the basic working tools of a system administrator.
  • Understanding of the specifics of deploying, configuring and maintaining networks built on Linux.
  • The ability to quickly solve emerging problems and ensure stable and uninterrupted operation of the system.
Test yourself on the entrance test and see the program for more details.


Top