Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Linux - Network: Configuration

Back


Networking Fundamental

Terminologies


Network Components


Network Configuration Tools

nmtui: Text Interface

nmtui01

nmtui01


nm-connection-editor

nm-connection-editor01


GNOME Settings

GNOME Settings


Hostname

/etc/hostname

hostname

Command

CMD Desc
hostname Display the Current Hostname
hostname -a Display the alias name
hostname -i Display IPv4 and IPv6 of the host.
hostname -I Display IPv4 of the host.
sudo hostname newhostname Set a Temporary Hostname
hostnamectl Display Hostname Information
sudo hostnamectl set-hostname newhostname Sets a new hostname and updates the /etc/hostname
sudo hostnamectl set-hostname "pretty_name" --pretty Set the Pretty Hostname
sudo hostnamectl set-hostname newstatichostname --static set a static hostname
sudo hostnamectl set-hostname newtransienthostname --transient set a transient hostname (temporary hostname for the current session)

Lab: Change Hostname

# display hostname
hostname
# rhelhost.localdomain

# display hostname info
hostnamectl
#  Static hostname: rhelhost.localdomain
#        Icon name: computer-vm
#          Chassis: vm
#       Machine ID: ca299475723c4510bf96994f9b0391d6
#          Boot ID: 8236fb4874fc4e958e092424c1617a84
#   Virtualization: vmware
# Operating System: Red Hat Enterprise Linux 8.10 (Ootpa)
#      CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
#           Kernel: Linux 4.18.0-553.30.1.el8_10.x86_64
#     Architecture: x86-64
# Display hostname
hostname
# rhelhost.localdomain

# Change hostname temporarily
sudo hostname newhost

# view the hostname in cf
cat /etc/hostname
# rhelhost.localdomain

# reboot
systemctl reboot

# Display hostname
hostname
# rhelhost.localdomain

# view the hostname in cf
cat /etc/hostname
# rhelhost.localdomain
# Display hostname info
hostnamectl
#  Static hostname: rhelhost.localdomain
#        Icon name: computer-vm
#          Chassis: vm
#       Machine ID: ca299475723c4510bf96994f9b0391d6
#          Boot ID: db70d05de8e7435798baa3b443c97ea7
#   Virtualization: vmware
# Operating System: Red Hat Enterprise Linux 8.10 (Ootpa)
#      CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
#           Kernel: Linux 4.18.0-553.30.1.el8_10.x86_64
#     Architecture: x86-64


# Change the static hostname
sudo hostnamectl set-hostname newhostname

# Change pretty name
sudo hostnamectl set-hostname "pretty_name" --pretty

# Change transient name
sudo hostnamectl set-hostname newtransienthostname --transient

# Confirm
# hostname for current session
hostname
# newhostname

# confirm
cat /etc/hostname
# newhostname

hostnamectl
#    Static hostname: newhostname
#    Pretty hostname: pretty_name
# Transient hostname: newtransienthostname
#          Icon name: computer-vm
#            Chassis: vm
#         Machine ID: ca299475723c4510bf96994f9b0391d6
#            Boot ID: db70d05de8e7435798baa3b443c97ea7
#     Virtualization: vmware
#   Operating System: Red Hat Enterprise Linux 8.10 (Ootpa)
#        CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
#             Kernel: Linux 4.18.0-553.30.1.el8_10.x86_64
#       Architecture: x86-64


# reboot
systemctl reboot

# show hostname
hostname

cat /etc/hostname
# newhostname

hostnamectl
#  Static hostname: newhostname
#  Pretty hostname: pretty_name
#        Icon name: computer-vm
#          Chassis: vm
#       Machine ID: ca299475723c4510bf96994f9b0391d6
#          Boot ID: 5a82a02c3a634367991075db25be1cf1
#   Virtualization: vmware
# Operating System: Red Hat Enterprise Linux 8.10 (Ootpa)
#      CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
#           Kernel: Linux 4.18.0-553.30.1.el8_10.x86_64
#     Architecture: x86-64


DNS Service

Configuration File

/etc/hosts

IP_address  hostname  [aliases...]

/etc/resolv.conf

option value
nameserver 8.8.8.8
domain example.com
search example.net example.org example.edu example.gov
nameserver 192.168.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

/etc/nsswitch.conf

database: source1 source2 source3
hosts: files dns

Lab: Step-by-Step Domain Name Resolution

cat /etc/nsswitch.conf | grep dns
# hosts:      files dns myhostname
# networks:   files dns

cat /etc/resolv.conf
# search localdomain
# nameserver 192.168.204.2
# nameserver 8.8.8.8

cat /etc/hosts
# 192.168.204.10 localdomain

hostname
# localdomain

ping localdomain

ping abc.com

Lab: Setup DNS using nmcli

nmcli device status
# DEVICE  TYPE      STATE                   CONNECTION
# ens160  ethernet  connected               ens160
# ens224  ethernet  connected               static_con

nmcli connection down ens160
nmcli connection modify ens160 ipv4.dns 8.8.4.4
nmcli connection show ens160 | grep "ipv4.dns:"
# ipv4.dns:                               8.8.4.4
nmcli connection up ens160

# confirm
grep "nameserver" /etc/resolv.conf
# nameserver 8.8.4.4
# nameserver 192.168.204.2

DNS Lookup

CMD Desc
nmcli connection modify "id_name" ipv4.dns "dns_ip" Set the DNS ip
sudo nano /etc/resolv.conf Configure DNS server
grep "nameserver" /etc/resolv.conf Get DNS server
nslookup target_domain DNS lookup a domain name
nslookup target_domain nameserver DNS lookup a domain name with a nameserver
dig target_domain DNS lookup a domain name
host target_domain DNS lookup a domain name
dig -x ip_address Reverse lookup
host -v ip_address Reverse lookup
nslookup ip_address Reverse lookup

Lab: Lookup and Reverse Lookup Domain Name

# Get DNS server
grep "nameserver" /etc/resolv.conf
# nameserver 192.168.128.2

# query a domain name
nslookup google.com
# Server:         192.168.128.2
# Address:        192.168.128.2#53

# Non-authoritative answer:
# Name:   google.com
# Address: 142.251.32.78
# Name:   google.com
# Address: 2607:f8b0:400b:807::200e

# DNS lookup using a specific nameserver
nslookup google.com 192.168.128.2
# Server:         192.168.128.2
# Address:        192.168.128.2#53

# Non-authoritative answer:
# Name:   google.com
# Address: 142.251.41.78
# Name:   google.com
# Address: 2607:f8b0:400b:807::200e

dig google.com
# ; <<>> DiG 9.16.23-RH <<>> google.com
# ;; global options: +cmd
# ;; Got answer:
# ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48899
# ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

# ;; OPT PSEUDOSECTION:
# ; EDNS: version: 0, flags:; MBZ: 0x0005, udp: 4000
# ;; QUESTION SECTION:
# ;google.com.                    IN      A

# ;; ANSWER SECTION:
# google.com.             5       IN      A       172.217.165.14

# ;; Query time: 17 msec
# ;; SERVER: 192.168.128.2#53(192.168.128.2)
# ;; WHEN: Sat Feb 08 17:22:12 EST 2025
# ;; MSG SIZE  rcvd: 55

host google.com
# google.com has address 142.251.32.78
# google.com has IPv6 address 2607:f8b0:400b:807::200e
# google.com mail is handled by 10 smtp.google.com.


# perform a reverse lookup
dig -x 172.217.165.14
# ; <<>> DiG 9.16.23-RH <<>> -x 172.217.165.14
# ;; global options: +cmd
# ;; Got answer:
# ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7501
# ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

# ;; OPT PSEUDOSECTION:
# ; EDNS: version: 0, flags:; MBZ: 0x0005, udp: 4000
# ;; QUESTION SECTION:
# ;14.165.217.172.in-addr.arpa.   IN      PTR

# ;; ANSWER SECTION:
# 14.165.217.172.in-addr.arpa. 5  IN      PTR     yyz12s06-in-f14.1e100.net.

# ;; Query time: 8 msec
# ;; SERVER: 192.168.128.2#53(192.168.128.2)
# ;; WHEN: Sat Feb 08 17:26:16 EST 2025
# ;; MSG SIZE  rcvd: 95

host -v 8.8.8.8
# Trying "8.8.8.8.in-addr.arpa"
# ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63281
# ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

# ;; QUESTION SECTION:
# ;8.8.8.8.in-addr.arpa.          IN      PTR

# ;; ANSWER SECTION:
# 8.8.8.8.in-addr.arpa.   5       IN      PTR     dns.google.

# Received 62 bytes from 192.168.128.2#53 in 9 ms

nslookup 8.8.8.8
# 8.8.8.8.in-addr.arpa    name = dns.google.
# Authoritative answers can be found from:

Connection

/etc/sysconfig/network-scripts/


Commond


TOP