How to set up smartphones and PCs. Informational portal

Centos 7 remove network interface.

However, in order to solve them once and for all, we recommend, if technically possible, to allocate an IP-PBX with a white IP.

Attention: do this if you understand well what security is (You can read) and with iptables on YOU.

If the server does not have a second network card, then usually one can be purchased for little money. Buy a network card only from a well-known manufacturer, then it will be detected in the system without any problems and will serve you for a long time.


1. Definition of a network card in the system.

After inserting the network card and booting, enter the command: ifconfig. If the network is defined, then we will see, for example, this:

….



RX packets:222424 errors:0 dropped:0 overruns:0 frame:0
TX packets:3456 errors:0 dropped:0 overruns:0 carrier:0

RX bytes:45173795 (43.0 MiB) TX bytes:380609 (371.6 KiB)
Interrupt:225

2. IP address setting

This means that the network card has been identified, but does not yet have an IP address. We insert the wire from the provider to configure the external IP. For example, the provider gave us the following settings:

ip: 123.45.45.2
gw: 123.45.45.1
netmask: 255.255.255.252
dns: 123.45.44.1

Imagine that we are in another city and if we lose control, a business trip awaits us, or it will take a long time to explain to the user what needs to be done. Therefore, we do everything in stages.

Let's start editing the config:

nano /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:e0:4c:33:59:b0
IPADDR=123.45.45.2
NETMASK=255.255.255.252

Now we restart our eth1 interface:

# ifdown eth1
# ifup eth1

Check if the IP address is correct:

#ifconfig
….
eth1 Link encap:Ethernet HWaddr 00:E0:4C:33:59:B0
inet addr:123.45.45.2 Bcast:123.45.45.3 Mask:255.255.255.252
inet6 addr: fe80::2e0:4cff:fe33:59b0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:228286 errors:0 dropped:0 overruns:0 frame:0
TX packets:3508 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:46361012 (44.2 MiB) TX bytes:389499 (380.3 KiB)
Interrupt:225

Now we check the availability of the provider's gateway. What he issued, you still need to check:

# ping 123.45.45.1
PING 123.45.45.1 (123.45.45.1) 56 (84) bytes of data.
64 bytes from 123.45.45.1: icmp_seq=1 ttl=64 time=0.127 ms
64 bytes from 123.45.45.1: icmp_seq=2 ttl=64 time=0.127 ms

--- 123.45.45.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.127/0.127/0.127/0.000ms

Yep, it's all good. But again, this does not mean that we will be allowed on the Internet. We add a route, for example, to our router from where we work, through the new gateway 123.45.45.1.

# route add -host 87.250.250.203 gw 123.45.45.1

Check if the route has been added
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
87.250.250.203 123.45.45.1 255.255.255.255 UGH 0 0 0 eth1
192.168.192.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
123.45.45.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
0.0.0.0 192.168.192.1 0.0.0.0 UG 0 0 0 eth0

Let's ping 87.250.250.203 and traceroute 87.250.250.203, making sure everything goes well. To be sure, add routes to the DNS server that will be used and some other host on the Internet. If everything responds, then our gw lets you into the Internet. Now you can change the default route to a new one, and comment out the old one.

# nano /etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme BCM5723 Gigabit Ethernet PCIe
DEVICE=eth0
BOOTPROTO=none
HWADDR=2c:41:38:87:88:43
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.192.87
#GATEWAY=192.168.192.1
TYPE=Ethernet

# nano /etc/sysconfig/network-scripts/ifcfg-eth1
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:e0:4c:33:59:b0
IPADDR=123.45.45.2
NETMASK=255.255.255.252
GATEWAY=123.45.45.1

If everything is done correctly, then we reboot all network interfaces
# service network restart

Attention: make sure that the iptables rules allow you to make a connection from a foreign network. You can temporarily disable protection with the command: service iptables stop
And if everything went smoothly, then you can already connect via external IP.

Attention: there may be differences in the configuration, carefully approach this issue if the server is far away and there is no KVM.

3. Routing setup

So, we added the second interface, configured it. Now the task may arise, setting up traffic routing to a specific host or network through the old gateway (for example, traffic is cheaper there). To do this, you need to register a route. This is done with the route command.
#route add -host 95.11.13.5 gw 192.168.192.1 dev eth0

We do ping and traceroute (mtr) to the host 95.11.13.5. We see that the traffic goes through the specified gateway.

Note: it is often thought that this is the end of the setup, but after a reboot or restart of network interfaces, the routes fail. Here, adding to rc.local may not help either.
Correctly register routes "forever" like this.
We create a file:

#nano /etc/sysconfig/network-scripts/route-eth0
ADDRESS0=95.11.13.5
GATEWAY0=192.168.192.1
NETMASK0=255.255.255.255

We save. Now after service network restart this route will be registered automatically.

Note: ethX is the one that is on the same network as the gateway through which we want to send traffic

Linux users, spoiled by distributions like Ubuntu, have little to no networking trouble. The Internet is connected automatically at the time of installation of the distribution. The system itself finds network equipment and configures it. Approximately the same as it happens in the Windows operating system of relatively late releases.

In Centos, the situation is different - the user or administrator has to work with brains and pens. This is due to the practicality and minimalism of the distribution in some of its aspects. And also by the fact that it is designed for a relatively narrow circle of trained users. This OS is especially loved by system administrators in offices and in production. Throughout our short story, we will discuss how the network is configured in Centos.

Of course, our story will not be comprehensive, we will focus only on the main points, and we will leave the fine adjustment of the parameters for later. Many users encounter obstacles already at the first stage: the terminal reacts to ifconfig with an error. Like, there is no such team and that's it. Ifconfig must be run as system administrator with the "su -" prefix.

Learn more about configuration

All network setup in CentOs comes down to editing configuration files with names starting with "ifcfg-".

Let's start by editing the ifcfg-eth0 file located at /etc/sysconfig/network-scripts/. You can do this with vi or any other editor. There are two main types of network settings in CentOs - based on the DHCP protocol and for a static IP address. In the first case, the contents of this configuration file will need to be made as follows:

In the case of using DHCP, these lines will look like this:

There is one more configuration file that needs to be edited when setting up a network in CentOs. This file is /etc/sysconfig/network. Here you need to enter the following lines:

Be sure to restart the network interface. It is done like this:

DNS hints are set in a file called /etc/resolv.conf. DNS information is entered into this file in the following format:

Here, perhaps, is all that you need to know and be able to do for the initial network setup in CentOs. That is, nothing particularly harsh. Here is another command used to disable the network interface.

Which is described in the corresponding article, you need to perform a number of basic settings. One of which is setting up 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 CentOS, so this command must be run from the superuser (administrator) with the command:

The reason is that regular system users and the root user have different PATH environment variables (you can see the user's PATH with echo $PATH). After typing a Linux command, the shell will look in the user's PATH to try and find a command to run. It starts searching every directory in PATH until the target is found. Regular user commands are usually located in /usr/local/bin, /usr/bin and /bin. And the root user commands are located mainly in /usr/local/sbin, /usr/sbin, /sbin and the root PATH reflects this. So when you become root with "su -", you also take over the new PATH path to the main commands. And using only 'su' saves the user's PATH path by default, therefore, when trying to execute a program located in /usr/local/sbin, /usr/sbin, /sbin, the result will be: 'command not found' error. For a more detailed explanation, see the man page (man bash), especially the login shells section. Thus, you either have to specify the 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 family of operating systems, you need to know and understand that all hardware and software devices, as well as various parameters of the operating system itself and programs are stored in configuration files. Thus, interface configuration files control the software interfaces of individual network devices. When the OS is loaded, 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 opportunity to configure OS and hardware parameters.

Network interface setup

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

Reminder to make changes to the contents of the file in the editor vi- necessary:

  • press the "i" or "Insert" key
  • to exit edit 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 actions taken:

Network setup

We edit the network configuration file:

#vi /etc/sysconfig/network

Enter the following data:

NETWORKING="yes"
HOSTNAME="Your.Server.Name" or workstation

To apply the settings correctly (so that they take effect), we 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 is also worth knowing that network setup can be done more quickly, run these commands:

ifconfig eth0 192.168.X.X netmask 255.255.255.0

To disable the network interface, run:

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

In this case, to stop the network interface from working, it will be necessary to exit the dhclient program:

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

DNS setup

Open the 'resolv.conf' file:

Good day!

Setting up a network on CentOS is very easy. You need to edit one file and restart the network service. But first things first.

Network settings in CentOS are in the folder:

/etc/sysconfig/network-scripts/

Each network card has its own settings file: ifcfg-eth0, ifcfg-eth1 .... ifcfg-eth99. For the first or only network card, the configuration file will be named ifcfg-eth0. To edit it, type in the console:

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

Press the "i" button to enter edit mode and add one of the configurations below to the file.

Setting up a network with a static IP

A typical configuration would look like this:

DEVICE="eth0"//network card name
TYPE=Ethernet// type of network card
BOOTPROTO=none// autoconfiguration protocol (for example DHCP)
ONBOOT="yes"//enable at system boot
IPADDR=177. 61.211.162 //Static IP
NETMASK=255.255.192.0//Subnet mask
GATEWAY=177.61.192.1//Main gate
DNS1=8. 8.8.8 //DNS server
DNS2=8. 8.4.4

If your CentOS server is running inside your home LAN, then the subnet mask and gateway can be viewed on any other Windows or Linux machine. You can take any free IP address. If the server is connected to a provider or installed in a data center, all settings must be requested from the provider.

Setting up a network with dynamic IP

It's very rare to set up a network on CentOS with a dynamic IP, but I'll post the settings just in case:

DEVICE="eth0"//network card name
TYPE=Ethernet// type of network card
BOOTPROTO="dhcp"//autoconfiguration protocol
ONBOOT="yes"//enable at system boot

Applying new network settings

After you have made all the necessary changes to the ifcfg-eth0 file, press the "Esc" key to exit edit mode, then type ":wq" to exit the editor and save and press "Enter".

Now check the settings of the main configuration file:

vi /etc/sysconfig/network

It should contain the following content:

NETWORKING=yes
HOSTNAME=dev.site
//your hostname

In order for the changes to take effect, you must restart the network interface:

/etc/init.d/network restart

If you have any questions or need clarification - please, or leave a comment.

In this article, I will touch on a topical topic with which almost any initial work with the server begins. Configuring basic network settings in CentOS - ip address, dhcp, ipv6, dns, hostname, static routes, network cards and other network settings.

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. Network settings on CentOS 7 server
  2. How to get network settings via DHCP
  3. How to set up DNS on CentOS 7
  4. How to disable ipv6 on CentOS 7
  5. How to change hostname in CentOS 7
  6. Set Default Gateway on CentOS 7
  7. Network Manager on CentOS 7
  8. System config network tui on CentOS 7
  9. How to add a static route in CentOS 7
  10. How to configure 2 IP addresses on one interface
  11. How to do network restart in CentOS 7
  12. How to find IP address in CentOS 7
  13. What to do if CentOS does not see the network card?
  14. What to do if the network is not available in CentOS?
  15. Using traceroute, dig network utilities on CentOS
  16. Configuring 802.1Q VLANs on CentOS 7

Network settings on CentOS 7 server

The first time we encounter the network settings of a CentOS server is when we install. On the initial setup screen, there is a separate item regarding the configuration of network interfaces:

Going into it, we see a list of connected network cards. Each of them can be turned on with 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 satisfied with these settings, you can edit them by clicking configure(item 3 in the picture). Here you can also set hostname(item 2 in the picture):

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

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

Now consider another situation. The server, and accordingly the network configuration, was not made by you, 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 have installed from a distribution minimal, then when you try to view the network settings using the command ifconfig in the console you will see the following:

Bash: ifconfig: command not found

or in the 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 -y install net-tools.x86_64

Now you can see the network settings:

#ifconfig

eno16777728: flags=4163 mtu 1500
inet 192.168.159.129


RX packets 319 bytes 36709 (35.8 KiB)

TX packets 256 bytes 148817 (145.3 KiB)

lo: flags=73 mtu 65536

inet6::1 prefixlen 128 scopeid 0x10

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, then you can use a simpler command ip with parameters:

# ip addr

1:lo: mtu 65536 qdisc noqueue state UNKNOWN

inet 127.0.0.1/8 scope host lo

inet6::1/128 scope host
valid_lft forever preferred_lft forever
2:eno16777728: mtu 1500 qdisc pfifo_fast state UP qlen 1000

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 /etc/sysconfig/network-scripts directory and open the file for editing ifcfg-eth0. This file has the following content:

According to 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 settings:

BOOTPROTO with dhcp on noneDNS1 specified IPADDR dns server, configured static ip address PREFIX, specified GATEWAY subnet mask. set default gateway

For the changes to take effect, you need to reread the network settings:

Restarting network (via systemctl): [ OK ]

Check if the new network configuration has been applied:

#ifconfig:

eno16777728: 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 in order, the new network interface settings are set.

How to get network settings via DHCP

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

# /etc/init.d/network restart

Then we check if our client received the settings via dhcp.

How to set up DNS on CentOS 7

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

  • In the network card settings file ifcfg-eth0, which we edited several times earlier.
  • In the file /etc/resolv.conf

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, they 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 edit the resolv.conf file now 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 you need.

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 restarting 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 on CentOS 7

Protocol currently in active use ipv6 no, it is not needed in normal operation. Although we have been scared for many years that there are practically no free ip addresses left, but in reality there are still enough for everyone. So, for practical reasons, ipv6 is currently not needed on the server and can be disabled.

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

# netstat -tulnp



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, these are sshd, postfix and chronyd. Let's disable ipv6 for them and leave only ipv4.

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

#AddressFamily any
#ListenAddress 0.0.0.0

Let's comment them out and change them. It should turn out like this:

AddressFamily inet
ListenAddress 0.0.0.0

Now open the postfix configuration 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 disable ipv6 in CentOS. Open 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 by adding there:

NETWORKING_IPV6=no
IPV6INIT=no

Reboot and check the result:

# reboot# ifconfig

eno16777728: flags=4163 mtu 1500

ether 00:0c:29:7d:59:3f txqueuelen 1000 (Ethernet)
RX packets 2301 bytes 243024 (237.3 KiB)
RX 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 in order, 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 ipv4 ports. All right, our task is done.

How to change hostname in CentOS 7

By default, during installation, CentOS sets 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

All right, we have changed the hostname to centos.localhost

Set Default Gateway on CentOS 7

If for some reason, when configuring the network settings, you did not set the default gateway, then you can do it manually. First, let's check which default gateway is currently installed in the system:

# netstat -nr
Kernel IP routing table

0.0.0.0 149.154.71.254 0.0.0.0 UG 0 0 0 eth0
10.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun0
10.8.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
149.154.70.0 0.0.0.0 255.255.254.0 U 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 do not have it, or the wrong gateway is set in the Gateway field, then you can change it. Set the default gateway:

Route add default gw 192.168.0.1Network Manager on CentOS 7

CentOS has by default a service that manages all network connections - network manager. It constantly monitors network settings and uses the configuration management daemon to make appropriate changes to active network devices. It supports standard ifcfg configuration files.

List of network utilities and applications:

network manager Standard networking daemon nmtui

Simple Text Interface (TUI) for NetworkManager nmcli

Command line utility that allows users and scripts to interact with NetworkManager control center

GNONE Shell GUI Utility nm-connection-editor GTK+ 3 applications required for some tasks not supported by control-center

Users do not interact directly with NetworkManager on CentOS, but use graphical and command line utilities. One of these utilities is system config network tui.

System config network tui on CentOS 7

To manage network settings in CentOS, you can use a graphical utility nmtui.

Checking its presence in the system is very simple.

It is enough to run it in the console:

If you do not have it installed, then fixing it is very simple. Install in CentOS system config network tui:

# yum install NetworkManager-tui

Via tui you can specify any network settings that we did before through the command line and editing configuration files. Let's do that. We call the program:

Choose 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 finishing editing, save the settings by clicking OK.
If you select the item in 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.

How to add a static route in CentOS 7

You may need to add a static route to control routing on CentOS. This is easy enough to do with a 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

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 fact, 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

Check if 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.159.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777728

All right, the route has been added. But after a reboot, this static route will be removed. To prevent this from happening and to save the added routes, you need to write them to a special file. In the /etc/sysconfig/network-scripts folder, 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.255.0 UG 0 0 0 eno16777728
192.168.159.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777728

All right, the static route has been added.

How to configure 2 IP addresses on one interface

If you need to set up 2 IP addresses on the same interface in CentOS, then 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 errors 0 dropped 0 overruns 0 frame 0

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 errors 0 dropped 0 overruns 0 frame 0

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Let's add one more 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

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

# 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 network restart in CentOS 7

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

# /etc/init.d/network restart

The NetworkManager service will reread all network settings and apply the changes.

How to find IP address in CentOS 7

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

# ifconfig | grep net

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 net

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 found 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 reminder of your card there. Perhaps it is in the system, it's just not activated. You can activate it with nmtui, which I mentioned above.

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

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's also a chance that you won't see your card when you run the ifconfig command unless a network wire is plugged into that card. To see all interfaces for sure, you need to 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 see 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 in CentOS?

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

# ping 8.8.8.8

And in response you get:

Connect: Network is unreachable

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

# route add default gw 192.168.0.1

If it's not the gateway, then you need to check the network adapter settings. If there is no active adapter, then you will also receive a message that the network is down. You must have at least one network adapter configured correctly on your system. How to do this is written above.

Using traceroute, dig network utilities on 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 in the system. For example, the popular utility traceroute when you try to run 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 -y install traceroute

The same 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 need to install the package bind-utils:

# yum -y install bind-utilsSetting up 802.1Q VLAN on CentOS 7

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

# modprobe 8021q

If there are no error messages, then everything is in order. If the module is not found, the kernel modules must be rebuilt to include support for the required module.

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

#mcedit ifcfg-vlan4000

VLAN=yes
DEVICE=eno16777728.2000
BOOTPROTO=static
ONBOOT=yes
TYPE=Vlan
IPADDR=192.168.100.2
NETMASK=255.255.255.0

I draw your attention to the 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 vlan4000’.

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

# ifup vlan4000

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:eno16777728: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:7d:59:3f brd ff:ff:ff:ff:ff:ff
3: [email protected]: mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether 00:0c:29:7d:59:3f brd ff:ff:ff:ff:ff:ff

Everything is in order, the tagged interface is up. By analogy, you can create several more similar interfaces, remembering to change their names and addresses.

This concludes my voluminous material on the topic of setting up a network in CentOS.

I will be very glad to comments, remarks, amendments. They certainly will. By creating such materials, I first of all learn myself and improve my knowledge in the subject area. There may be errors and omissions somewhere, although I check everything on live systems while writing manuals, inaccuracies and typos are still possible.

Many thanks for the article: http://serveradmin.ru

Top Related Articles