Manage networking and hostname

TIPS & TRICKS

To search the contents of the man pages

# man -k searchterm 
# man -K searchterm

Manage networking

Manage networking Example 1

| Assign hostname and ip address for your virtual machine.
| - Hostname: servera.lab.example.com
| - Ip address: 192.168.1.42
| - Mask: 255.255.255.0
| - Gateway: 192.168.1.1
| - NameServer: 192.68.1.200

On console (not remote console) :

# hostnamectl set-hostname servera.lab.example.com
# hostnamectl

Note the interface with the ethernet type:

# nmcli connection show
# nmcli connection modify enp0s8 ipv4.addresses 192.168.1.42/24
# nmcli connection modify enp0s8 ipv4.gateway 192.168.1.1
# nmcli connection modify enp0s8 ipv4.dns 192.68.1.200
# nmcli connection modify enp0s8 ipv4.method manual // DON'T FORGET !

Note:
If you need to add several IP on a same interface, for example with DNS:

# nmcli connection modify enp0s8 ipv4.dns +192.168.1.43
# nmcli connection modify enp0s8 ipv4.dns +192.168.1.49

Or you need to delete several IP on a same interface, for example with DNS:

# nmcli connection modify enp0s8 ipv4.dns -192.168.1.40

If needed, add autoconnect :

# nmcli connection modify enp0s8 connection.autoconnect yes

UP the connexion, important:

# nmcli connection up enp0s8

From an other server or terminal, check @IP, gateway and DNS:

# ping 192.168.1.42
# ping 192.168.1.1
# ping 192.68.1.200

Then reboot:

# reboot

Then re-test ping from an other server. Then connect to the host and verify configuration with:

# ip a
# hostnamectl status

New created connection are writted in /etc/NetworkManager/system-connections/ with a big N:

# ls -l /etc/NetworkManager/system-connections/
total 12
-rw-------. 1 root root 288 Nov 14 15:19 enp0s8.nmconnection
-rw-------. 1 root root 242 Nov 14 15:10 MyCon.nmconnection

The DNS have been writted in /etc/resolv.conf:

# cat /etc/resolv.conf
# Generated by NetworkManager
search home.arpa lab.example.com
nameserver 192.68.1.200

Manage networking Example 2

| Please create new network connection using provided values:
| - IP: 192.168.1.44/24
| - Gateway: 192.168.1.255
| - DNS server: 192.168.1.250
| - Interface: eth0

That command creates a new connection for a specific interface. The interface is specified: “eth0”, you must specify with ifname the interface where the new connection will be created, the type “ethernet” and a name for the connection (here eth0, same as the interface). You can specify autoconnect:

# nmcli connection add con-name eth0 ifname eth0 type ethernet ipv4.method manual ipv4.addresses 192.168.1.44/24 ipv4.gateway 192.168.1.255 ipv4.dns 192.168.1.250 connection.autoconnect yes

If needed, configure autoconnect :

# nmcli connection modify eth0 connection.autoconnect yes
# nmcli connection modify eth0-old connection.autoconnect no

At the final stage it is wise to start this connection:

# nmcli con show --active      # to check if the connection is not up 
# nmcli con up eth0

New created connection are writted in /etc/NetworkManager/system-connections/ with a big N:

# ls -l /etc/NetworkManager/system-connections/
total 12
-rw-------. 1 root root 288 Nov 14 15:19 enp0s8.nmconnection
-rw-------. 1 root root 225 Nov 14 15:38 eth0.nmconnection
-rw-------. 1 root root 242 Nov 14 15:10 MyCon.nmconnection

The DNS have been writted in /etc/resolv.conf:

# cat /etc/resolv.conf
# Generated by NetworkManager
search home.arpa lab.example.com
nameserver 192.68.3.200
nameserver 192.168.1.250

Manage networking Example 4

| Update the /etc/hosts file on both server and client.
| Add the IP addresses assigned to both connections and map them to hostnames.
| Test connectivity from server to client and from client to server using their IP addresses and then their hostnames

On Server

# vim /etc/hosts
172.10.10.120 server.example.com server
172.10.10.121 client.example.com client

On client :

# vim /etc/hosts 
172.10.10.121 client.example.com client
172.10.10.120 server.example.com server

Documentations

Internet
Git
ChatGPT

> Partager <