[LINUX] Network settings and confirmation in CentOS7

environment

Execution result


[root@CENTOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@CENTOS7 ~]#

1. Host name

1.1. Confirmation of host name

hostname Or cat /etc/hostname

Execution result


[root@CENTOS7 ~]# hostname
CENTOS7
[root@CENTOS7 ~]#

Execution result


[root@CENTOS7 ~]# cat /etc/hostname
CENTOS7
[root@CENTOS7 ~]#

1.2. Change the host name

nmcli general hostname <hostname> Or hostnamectl set-hostname <hostname>

Execution result


[root@CENTOS7 ~]# nmcli general hostname CENTOS7AF
[root@CENTOS7 ~]# hostname
CENTOS7AF
[root@CENTOS7 ~]# cat /etc/hostname
CENTOS7AF
[root@CENTOS7 ~]#

Execution result


[root@CENTOS7 ~]# hostnamectl set-hostname CENTOS7AF
[root@CENTOS7 ~]# hostname
centos7af
[root@CENTOS7 ~]# cat /etc/hostname
centos7af
[root@CENTOS7 ~]#

For hostnamectl set-hostname <hostname>, it was set in lowercase.

2. Network interface

2.1. List of network physical interfaces (devices)

nmcli device

Execution result


[root@CENTOS7 ~]# nmcli device
DEVICE  TYPE      STATE     CONNECTION
enp0s3 ethernet connected enp0s3
lo loopback No management--
[root@CENTOS7 ~]#

2.2 Detailed display of network physical interface (device)

nmcli device show <device name>

Execution result


[root@CENTOS7 ~]# nmcli device show enp0s3
GENERAL.DEVICE:                         enp0s3
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         08:00:27:57:A3:39
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (Connected)
GENERAL.CONNECTION:                     enp0s3
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveCo
WIRED-PROPERTIES.CARRIER:on
IP4.ADDRESS[1]:                         192.168.0.11/24
IP4.GATEWAY:                            192.168.0.1
IP4.ROUTE[1]:                           dst = 192.168.0.0/24, nh = 0.0.0.0, mt =
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.0.1, mt =
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP6.ADDRESS[1]:                         fe80::2eca:a058:c18f:fd7e/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table
[root@CENTOS7 ~]#

2.3. List of network logical interfaces (connections)

nmcli connection

Execution result


[root@CENTOS7 ~]# nmcli connection
NAME    UUID                                  TYPE      DEVICE
enp0s3  0f174b12-5dc6-40c9-99fc-06c6ce550c24  ethernet  enp0s3
[root@CENTOS7 ~]#

2.4. Detailed display of network logical interface (connection)

nmcli connection show <connection name>

Execution result


[root@CENTOS7 ~]# nmcli connection show enp0s3
connection.id:                          enp0s3
connection.uuid:                        0f174b12-5dc6-40c9-99fc-06c6ce550c24
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              enp0s3
connection.autoconnect:Yes
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   1584364512
connection.read-only:No
connection.permissions:                 --
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:unknown
connection.lldp:                        default
connection.mdns:                        -1 (default)
connection.llmnr:                       -1 (default)
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --
802-3-ethernet.auto-negotiate:No
802-3-ethernet.mac-address:             --
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist:   --
802-3-ethernet.mtu:Automatic
802-3-ethernet.s390-subchannels:        --
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:            --
802-3-ethernet.wake-on-lan:             default
802-3-ethernet.wake-on-lan-password:    --
ipv4.method:                            manual
ipv4.dns:                               8.8.8.8,8.8.4.4
ipv4.dns-search:                        --
ipv4.dns-options:                       ""
ipv4.dns-priority:                      0
ipv4.addresses:                         192.168.0.11/24
ipv4.gateway:                           192.168.0.1
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --
ipv4.ignore-auto-routes:No
ipv4.ignore-auto-dns:No
ipv4.dhcp-client-id:                    --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:Yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.never-default:No
ipv4.may-fail:Yes
ipv4.dad-timeout:                       -1 (default)
ipv6.method:                            auto
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       ""
ipv6.dns-priority:                      0
ipv6.addresses:                         --
ipv6.gateway:                           --
ipv6.routes:                            --
ipv6.route-metric:                      -1
ipv6.route-table:                       0 (unspec)
ipv6.routing-rules:                     --
ipv6.ignore-auto-routes:No
ipv6.ignore-auto-dns:No
ipv6.never-default:No
ipv6.may-fail:Yes
ipv6.ip6-privacy:                       0 (disabled)
ipv6.addr-gen-mode:                     stable-privacy
ipv6.dhcp-duid:                         --
ipv6.dhcp-send-hostname:Yes
ipv6.dhcp-hostname:                     --
ipv6.token:                             --
proxy.method:                           none
proxy.browser-only:No
proxy.pac-url:                          --
proxy.pac-script:                       --
GENERAL.NAME:                           enp0s3
GENERAL.UUID:                           0f174b12-5dc6-40c9-99fc-06c6ce550c24
GENERAL.DEVICES:                        enp0s3
GENERAL.STATE:Activated
GENERAL.DEFAULT:Yes
GENERAL.DEFAULT6:No
GENERAL.SPEC-OBJECT:                    --
GENERAL.VPN:No
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveCo
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings
GENERAL.ZONE:                           --
GENERAL.MASTER-PATH:                    --
IP4.ADDRESS[1]:                         192.168.0.11/24
IP4.GATEWAY:                            192.168.0.1
IP4.ROUTE[1]:                           dst = 192.168.0.0/24, nh = 0.0.0.0, mt =
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.0.1, mt =
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP6.ADDRESS[1]:                         fe80::2eca:a058:c18f:fd7e/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table
[root@CENTOS7 ~]#

The command to change the above settings is as follows. nmcli connection modify <connection name> <item name> <value>

Change IP address to 192.168.0.12/24 nmcli connection modify enp0s3 ipv4.address 192.168.0.12/24

Execution result


[root@CENTOS7 ~]# nmcli connection modify enp0s3 ipv4.address 192.168.0.12/24
[root@CENTOS7 ~]#

Changed DNS server to 208.67.222.222 and 208.67.220.220 nmcli connection modify enp0s3 ipv4.dns "208.67.222.222 208.67.220.220"

Execution result


[root@CENTOS7 ~]# nmcli connection modify enp0s3 ipv4.dns "208.67.222.222 208.67.220.220"
[root@CENTOS7 ~]#

It will take effect by restarting NetworkManager.

systemctl restart NetworkManager

Execution result


[root@CENTOS7 ~]# systemctl restart NetworkManager
[root@CENTOS7 ~]#

With the above settings, changing the IP address required restarting the interface connection (inactive → active).

You can manually set the interface connection to active / inactive with the following command.

Deactivate the interface connection. nmcli connection down <connection name>

Execution result


[root@CENTOS7 ~]# nmcli connection down enp0s3
Connect'enp0s3'Was successfully deactivated(D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@CENTOS7 ~]#

Activate the interface connection. nmcli connection up <connection name>

Execution result


[root@CENTOS7 ~]# nmcli connection up enp0s3
The connection was activated successfully(D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@CENTOS7 ~]#

2.5. Check network interface (instead of old ifconfig)

ip addr show

Execution result


[root@CENTOS7 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:57:a3:39 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.11/24 brd 192.168.0.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::2eca:a058:c18f:fd7e/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
[root@CENTOS7 ~]#

3. Network settings using TUI (text user interface)

You can set the network with TUI (text user interface) with the following command.

nmtui

[root@CENTOS7 ~]# nmtui

01.png

4. Other

CentOS7 does not include network related commands such as ʻifconfig, route, netstat, and ʻarp. These commands are made available by adding the "net-tools" package.

yum install net-tools

In an environment where the "net-tools" package is not installed, use commands such as "ip, ss" included in the "iproute2" package.

Command correspondence table

net-tools iproute2
ifconfig ip addr、ip link
route ip route
netstat ss
netstat -i ip -s link
arp ip neighbor

that's all

Recommended Posts

Network settings and confirmation in CentOS7
CentOS 7 basic settings after network settings
Teaming (LACP) settings in CentOS 8
[RHEL / CentOS 8] Network settings memo
CentOS 7 NW settings
CentOS 7 network initialization
Create initial settings and staff apps in Django
CentOS8 server construction (network opening and package update)
Put matplotlib in Centos7.
Initial settings for using Python3.8 and pip on CentOS8
goland and Docker settings
CentOS version confirmation command
Easy HTTP server and Systemd autostart settings in Go
Neural network to understand and implement in high school mathematics
Clipping and normalization in TensorFlow
Remote related settings in pycharm
Settings often used in Jupyter
Install Python 3.7 and Django 3.0 (CentOS)
Stack and Queue in Python
Neural network implementation in python
Unittest and CI in Python
django timezone and language settings
Tomcat installation and autostart settings
Correspondence record of minor troubles in Linux installation and settings, etc.