[LINUX] [CentOS] Network check / change command [RHEL]

Sento-kun

20180516182359.jpg This is a network-related setting / confirmation method for Akabou Boy.

It seems that it is recommended to use NetworkManager from version 7, but you can also set it by editing the file as before 7.


table of contents

--HOSTNAME confirmation / setting

--IP settings (using NetworkManager)

--IP settings (file editing)

--Addition of static route

--DNS settings


HOSTNAME confirmation / setting

hostnamectl

You can see the kernel and OS information all at once.

Output example


[root@host01 /]# hostnamectl
Static hostname: host01
Icon name: computer-vm
Chassis: vm
Machine ID: 07346a5e12704a78a073eb9f111d5765
Boot ID: 848c64cbc5d942d2a7064fbf42540590
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-693.el7.x86_64
Architecture: x86-64

hostname host name

You can change the host name with, but it will be restored when you reboot. There is / etc / hostname </ font> as a configuration file, but this is not reflected. If you want to change it permanently

hostnamectl set-hostname --static host name

Set with. This will also be reflected in / etc / hostname. Also,

/etc/sysconfig/network



HOSTNAME=hostname

It will be reflected even if it is described as. Orders in the cloud may be listed in this file by default. Well, it doesn't matter which one.

IP settings (using NetworkManager)

You can set it using the nmcli command or the GUI setting tool nmtui.

systemctl start NetworkManager

Start the service with.

systemctl start NetworkManager

Check the network with.

Output example


[root@host01 ~]# nmcli
ens160:Connected to ens160
"VMware VMXNET3 Ethernet Controller"
ethernet (vmxnet3), 00:50:56:8D:FF:13, hw, mtu 1500
ip4 default
inet4 192.168.1.100/24
inet6 fe80::250:56ff:fe8d:ff13/64

lo:No management
"lo"
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

To get information about known devices"nmcli device show"Use the.
To get an overview of active connection profiles"nmcli connection show"Use the.

For more information on how to use it, nmcli(1)And nmcli-examples(5)See the man page for.

He politely explains the options. ..

nmcli device show
nmcli connection show

You can check the network device with.

nmcli c modify eth0 ipv4.addresses 192.168.1.100/24

IP setting of eth0 with.

nmcli c modify eth0 ipv4.gateway 192.168.1.1

Default setting.

nmcli c modify eth0 ipv4.dns 192.168.1.10

DNS settings in.

nmcli connection reload

Reflect the setting with. The settings here are described in / etc / sysconfig / network-scripts / ifcfg-eth0 </ font>.

Next is the setting in nmtui.

nmtui

You can edit the connection and change the host name with TUI. You can click while looking at the setting items. 20180516182549.jpg Like this.

IP settings (file editing)

I think some people say, "I don't need NetworkManager!", So I'll post the conventional method as well.

ip a

Check the address etc. with. If you install it, you can use ifconfig, but if you get used to it, this is easier.

/etc/sysconfig/network-scripts/ifcfg-eth0 Edit and set. eth0 is the corresponding device name. Once the NIC is added, you will have to create a configuration file with the name of that device. That is troublesome. I'm not sure about many parameters, but basically I wonder if the following parameters are all right.

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


DEVICE=eth0
ONBOOT=yes           #Enabled at OS startup
TYPE=Ethernet
BOOTPROTO=none       #Specify IP directly
IPADDR=192.168.1.100
PREFIX=24
NM_CONTROLLED=NO     #Do not use NetworkManager

If you do not use IPv6, you can delete each item. The part of PREFIX is NETMASK=255.255.255.0 It can also be written as.
Also, if you want to set an IP alias IPADDR1=192.168.1.111 PREFIX1=24 It can be set by adding as follows.

The default gateway setting is GATEWAY=192.168.1.1 DEFROUTE=yes You can set it by adding, but if there are multiple NICs, it is better to describe it in one of the following files.

/etc/sysconfig/network



GATEWAY=192.168.1.1

After editing the file, restart the service.
systemctl restart network

# Add static route ``` route add -net 192.168.99.0/24 gw 192.168.0.254 eth0 ``` `route add -net IP address / subnet gw Destination router address Outgoing device name` You can add it temporarily with. You can also set it with the ip route command, but these will disappear after a reboot.
If you want to add it permanently

/etc/sysconfig/network-scripts/route-eth0



192.168.9.0/24 via 192.168.0.254 dev eth0

Described as. You can omit dev eth0 because you have already specified it in the file.

ip route

Check the routing table with.

DNS settings

It can be described in the ifcfg file, but it is generally described in /etc/resolv.conf </ font>.

/etc/resolv.conf


nameserver 10.70.71.107
nameserver 10.70.71.108

Set with.

nslookup

Confirm with. If there is no command, install bind-utils </ font> with yum etc. You can also look up name resolution with the dig, host commands.


that's all.