Networking
Networking
List IP address(es):
ip addr show
Bring interface up:
ip link set <interface> up
Example:
ip link set enp0s5 up
Bring interface down:
ip link set enp0s5 down
Add an IP address to an interface:
ip addr add <ip_address>/<prefix_length> dev <interface>
Example:
ip addr add 192.168.1.10/24 dev enp0s5
Remove an IP address from an interface:
ip addr del <ip_address>/<prefix_length> dev <interface>
Show the routing table
ip route show
Display details for a specific route:
ip route get <destination>
Add a route:
ip route add <destination> via <gateway> dev <interface>
Example:
ip route add 10.0.0.0/24 via 192.168.1.1 enp0s5
Remove a route:
ip route del <destination> via <gateway> dev <interface>
Checking DHCP behaviour:
Process is Discover -> Offer -> Request -> Acknowledge
On Ubuntu system:
journalctl -b -u systemd-networkd
On CentOS
journalctl -b -u NetworkManager.service
PING:
- the protocol is called ICMP (Internet Control Message Protocol)
- ping program will send a package (IMCP: “Echo request”) to the destination
- if the destination supports the ICMP protocol, it should reply with ICMP “echo reply” packet
ping 8.8.8.8
TRACEROUTE
- Network diagnostic tool
- Determines the path taken by data packets from source to destination
- Identifies network latency and potential routing issues
- Indicates the position of the router in the path (hop number)
- Identifies the intermediate router (router ip address / hostname)
- RTT values: Latency measurements for each packet sent
traceroute google.com
traceroute to google.com (142.251.38.142), 30 hops max, 60 byte packets
1 _gateway (192.168.100.2) 10.339 ms 10.086 ms 7.457 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
[tomik@localhost ~]$ traceroute -I google.com
traceroute to google.com (142.251.141.174), 30 hops max, 60 byte packets
1 _gateway (192.168.100.2) 2.883 ms 48.892 ms *
2 192.168.0.1 (192.168.0.1) 4.854 ms * *
3 * * *
4 ip-86-49-54-209.bb.vodafone.cz (86.49.54.209) 26.769 ms 26.677 ms 27.428 ms
5 osu0b-ra-01-ae15.net.vodafone.cz (185.188.186.103) 32.141 ms 32.049 ms 32.554 ms
6 ostra-rc-01-ae42.net.vodafone.cz (185.188.187.86) 31.708 ms 24.466 ms 24.304 ms
7 a0sit-rc-01-ae1.net.vodafone.cz (185.188.187.253) 24.111 ms 24.679 ms 24.414 ms
8 * * *
9 cst2-191-34.cust.vodafone.cz (31.30.191.34) 37.513 ms 37.251 ms 36.936 ms
10 lcprga-ag-in-f14.1e100.net (142.251.141.174) 34.547 ms 32.386 ms 32.153 ms
[tomik@localhost ~]$
The Port Scanner Nmap
- will find out which ports are open on another system
- if the port is open, we will get a message back from the server
- allows us to identify open ports and services that are available on the target system
- by default it will scan the most common 1000 TCP ports
nmap [hostname/IP]
- we can also specify port(s) manually:
nmap -p [port] [hostname/IP]
nmap -p [port1], [port2] [hostname/IP]
nmap -p [port1]-[port2] [hostname/IP]
- to scan all ports:
nmap -p - [hostname/IP]
- to scan range of IP addresses:
nmap [first IP]-[last IP (last number)]
nmap 192.168.1.1-100
We can choose between different types of scans:
- -sS (TCP-SYN-Scan):
- this is default scan method, if available
- Nmap builds the packets and sends them
- relatively fast
- sends a SYN packet to establish a TCP connection, but doesn’t follow through with full connection
- but we might need additional privileges (root)
- If we receive a:
- SYN/ACK: This port is open
- RST (reset) message: This port is closed
- No message: This port is probably blocked / filtered
[tomik@localhost ~]$ nmap -sS localhost
You requested a scan type which requires root privileges.
QUITTING!
[tomik@localhost ~]$ sudo !!
sudo nmap -sS localhost
[sudo] password for tomik:
Starting Nmap 7.92 ( https://nmap.org ) at 2026-10-05 11:51 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000022s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 999 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
Nmap done: 1 IP address (1 host up) scanned in 0.30 seconds
[tomik@localhost ~]$
- -sT (TCP-connect-scan):
- The default, if SYN-scan is not possible:
- user has not enough permissions to do a SYN-scan
- We’re trying to scan an IPv6 network
- Nmap is using functionality of the operating system to create a connection
- This means we do a full handshake with the remote server:
- SYN, SYN-ACK, ACK
- and then just close the connection
- be slower
- can cause crashing at the other side
- might cause logs at the other side
- The default, if SYN-scan is not possible:
- -sU (UDP-scan):
- we can use this to scan for open UDP ports
- we send a UDP packet to the remote destionation
- if we get reply, the port will be marked as “open”
- if we get an error back, we will mark this port as “filtered”
- if we don’t get a reply, we will mark the port as “open|filtered”
- scanning is extremely slow
- need to test each port multiple times as our request might have gotten lost on the way
[tomik@localhost ~]$ sudo nmap -sU localhost [sudo] password for tomik: Starting Nmap 7.92 ( https://nmap.org ) at 2026-10-05 12:09 CEST Nmap scan report for localhost (127.0.0.1) Host is up (0.000053s latency). Other addresses for localhost (not scanned): ::1 All 1000 scanned ports on localhost (127.0.0.1) are in ignored states. Not shown: 1000 closed udp ports (port-unreach)
Nmap done: 1 IP address (1 host up) scanned in 0.29 seconds ```
DNS records
- A - Maps a domain name to an IPV4 address
- AAAA - Maps a domain name to an IPV6 address
- CNAME - provides an alias for another domain name
- MX - specifies mail servers for a domain
- NS - lists authoritative name servers for a domain
You can use program host to check more available details
[tomik@localhost ~]$ host google.com
google.com has address 142.251.209.14
google.com has IPv6 address 2a00:1450:4014:800::200e
google.com mail is handled by 10 smtp.google.com.
[tomik@localhost ~]$ host -a google.com
Trying "google.com"
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47594
;; flags: qr rd ra; QUERY: 1, ANSWER: 35, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;google.com. IN ANY
;; ANSWER SECTION:
google.com. 246 IN A 74.125.29.139
google.com. 246 IN A 74.125.29.101
google.com. 246 IN A 74.125.29.113
google.com. 246 IN A 74.125.29.100
google.com. 246 IN A 74.125.29.138
google.com. 246 IN A 74.125.29.102
google.com. 246 IN AAAA 2a00:1450:400a:1000::65
google.com. 246 IN AAAA 2a00:1450:400a:1000::8a
google.com. 246 IN AAAA 2a00:1450:400a:1000::8b
google.com. 246 IN AAAA 2a00:1450:400a:1000::71
google.com. 246 IN TXT "onetrust-domain-verification=0d477fe608074e6f9c12bca7826035cc"
google.com. 246 IN TXT "Z29vZ2xl"
google.com. 246 IN TXT "work-accounts-domain-verification=Tcj6JjIMZOw2KsSEw2Nt2rLae89tN6"
google.com. 246 IN TXT "arcules-domain-verification=2R4t5G7nI6tRCo61lpxxbLksPYstxhGmtV75cpr8x9K"
google.com. 246 IN TXT "docusign=1b0a6754-49b1-4db5-8540-d2c12664b289"
google.com. 246 IN TXT "globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8="
google.com. 6 IN SOA ns1.google.com. dns-admin.google.com. 993157628 900 900 1800 60
google.com. 21546 IN NS ns2.google.com.
google.com. 246 IN TXT "_r4rd1pvwyrpi7sw4a3hzmw8e51yh9td"
google.com. 246 IN TXT "onetrust-domain-verification=6d685f1d41a94696ad7ef771f68993e0"
google.com. 21546 IN NS ns4.google.com.
google.com. 246 IN TXT "google-site-verification=4ibFUgB-wXLQ_S7vsXVomSTVamuOXBiVAzpR5IZ87D0"
google.com. 246 IN TXT "v=spf1 include:_spf.google.com ~all"
google.com. 246 IN TXT "docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e"
google.com. 246 IN TXT "google-site-verification=TV9-DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ"
google.com. 21546 IN NS ns1.google.com.
google.com. 246 IN TXT "google-site-verification=wD8N7i1JTNTkezJ49swvWW48f8_9xveREV4oB-0Hf5o"
google.com. 246 IN TXT "facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95
google.com. 246 IN TXT "apple-domain-verification=30afIBcvSuDV2PLX"
google.com. 246 IN MX 10 smtp.google.com.
google.com. 21546 IN TYPE65 \# 13 00010000010006026832026833
google.com. 21546 IN CAA 0 issue "pki.goog"
google.com. 21546 IN NS ns3.google.com.
google.com. 246 IN TXT "MS=E4A68B9AB2BB9670BCE15412F62916164C0B20BB"
google.com. 246 IN TXT "cisco-ci-domain-verification=47c38bc8c4b74b7233e9053220c1bbe76bcc1cd33c7acf7acd36cd6a5332004b"
Received 1575 bytes from 8.8.8.8#53 in 32 ms
[tomik@localhost ~]$
- DNS by hand
- we can manually send out DNS queries
- this is a nice way to experience how DNS query is resolved
- for this, we can use the dig program
- let’s try to resolve google.com!
- we will first have to pick a root server that we want to query:
dig @a.root-servers.net com NS
- then we can query the TLD nameserver of the .com domain:
dig @e.gtld-servers.net google.com NS
dig @ns1.google.com google.com any
SSH server
-
ssh run by default on port 22
-
there is recommended from security reason to change the port - to avoid scanners and attacks
-
we should change the port to something else
-
we can edit sshd config on the following file:
- /etc/sshd/sshd_config
-
UBUNTU setting
-
there we can uncomment the line “#Port 22”, and replace it with something else, for example: Port 222
-
then we need to restart sshd:
- first, test the configuration: sshd -t
- and then restart sshd: systemctl restart sshd
-
now connect to the server:
- ssh username@ip_address -p 222
-
but be careful:
- sometimes, firewalls of your internet provider /company/ … might just block “uncommon” ports
-
if you want to monitor the log file:
- all of this is stored in /var/log/auth.log (for ubuntu) and /var/log/secure (for CentOS)
- you can grep for “sshd” in this file
-
**CentOS setting
- there we can uncomment the line “#Port 22”, and replace it with something else, for example: Port 222 - do not save changes yet
- use command :
- semanage port -a -t ssh_port_t -p tcp 222
- be sure policycoreutils are installed
- sudo dnf install policycoreutils
- if firewall is running we need to configure other staffs:
- sudo systemctl status firewalld
- sudo firewall-cmd –add-port=222/tcp –permanent
- sudo firewall-cmd –reload
- now you can save the file sshd_config
- sudo systemctl restart sshd
- then you can try to connect to server with new port
- ssh username@ip_address -p 222
- now we need to remove 22 port as it si not needed more
- sudo firewall-cmd –remove-service=ssh –permanent
- sudo firewall-cmd –reload
-
**No Root login **
- you can set no root login via ssh again in /etc./sshd/sshd_config
- PermitRootLogin No
- you can set no root login via ssh again in /etc./sshd/sshd_config
-
Whitelist users:
- you can again set it in /etc/sshd/sshd_config
- AllowUsers tom tomik tobik
- you can again set it in /etc/sshd/sshd_config
-
Hw to not lock ourselves out:
- when you play with ssh setting always try to keep open second ssh session
-
SSH: Key auth:
- we generate Private and Public key which we can use for authentication!
- generate key pair:
- ssh-keygen -t rsa -b 4096
- Private key: ~/.ssh.id_rsa
- Public key: ~/.ssh/id_rsa.pub
- now we need to transfer the public key into the file
- ~/.ssh/authorized_keys on the remote server
- Manual version:
- connect to the server, create the file (if neede)
- copy public key into that file
- we also should set the permissions quite restrictive:
- chmod 700 ~/.ssh
- chmod 600 ~/.ssh/authorized_keys
- Easiest way:
- ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
- ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
- ssh-keygen -t rsa -b 4096
-
SSH: Prevent connection dorps:
- we can configure “keep-alive” packets, either on server side, or on client side
- best practice: we configure this for the client side
- we need to open one of the config files for the ssh program (not sshd!)
- user config: ~/.ssh/config (should have
chmod 600) - system wide config: /etc/ssh/ssh_config
- there we add the following content:
Host * ServerAliveInternal 60 ServerAliveCountMax 3
- user config: ~/.ssh/config (should have
- this will:
- send an empty packet every 60 seconds to keep the connection open (keep-alive packet)
- allow up to 3 of those keep-alive packets to fail, and the connection will remain open
-
SSH: SFTP:
- it is enabled on most server that support ssh
- perfect way to transfer data from / to a remote server
- we could use GUI for this:
- usually through protocol names sftp://, ssh://, fish://
- Or we can also use the program
scp
scp -r user@server:folder [destination]
# -r: copy subfolders too
# Example:
scp [email protected]:/home/jack/important.txt document.txt
# If SSH port is changed we have to define also SSH port
scp -P 222 [email protected]:/home/jack/importatnt.txt document.txt