Skip to main content

Networking

Get DNS record information​

dig domainName
tip

The record type can also be specified for non-A records, i.e. dig _acme-challenge.www TXT

Useful options​

  • @server - Set DNS server to use for query, i.e. dig @1.1.1.1 domainName.
  • -x ipAddr - Reverse lookup.

Firewalld​

Persistent vs temporary changes​

By default, changes are applied to the runtime configuration only and are lost on reload or reboot. Add --permanent to write the change to the saved configuration (it is not applied to the running firewall until reloaded).

Save the current runtime configuration as permanent

sudo firewall-cmd --runtime-to-permanent

Reload configuration​

sudo firewall-cmd --reload
note

Reloading applies the permanent configuration and discards runtime-only changes.

Zones​

Show active zones​

sudo firewall-cmd --get-active-zones

Show rules of all zones or a specific zone​

sudo firewall-cmd --list-all-zones
sudo firewall-cmd --zone=public --list-all

Add a zone​

sudo firewall-cmd --permanent --new-zone=myZone
note

A new zone is only available after reloading.

Zone matching order​

For each incoming packet, firewalld picks the zone using the first match in this order:

  1. Source - a zone with a source matching the packet's source address.
  2. Interface - the zone the incoming interface is assigned to.
  3. Default zone - used when neither of the above matches.

Get / set default zone​

sudo firewall-cmd --get-default-zone
sudo firewall-cmd --set-default-zone=public

Traffic rules​

Add a port​

sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
warning

If --zone is omitted, the change is applied to the default zone. This applies to ports, services, rich rules and other zone-scoped options too.

Add a service​

sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --get-services # list available services

Add a rich rule​

Express policies that services and ports alone can't: match by source/destination address, family, service or port, and apply accept, reject, drop. They also support rate limiting and timeouts.

sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port port="8080" protocol="tcp" accept'
sudo firewall-cmd --zone=public --list-rich-rules
tip

Use --remove-port, --remove-service and --remove-rich-rule (with the same arguments) to undo each of these.

Add or remove a source​

Assigns traffic coming from an address or network to a zone.

sudo firewall-cmd --permanent --zone=trusted --add-source=192.168.1.0/24
sudo firewall-cmd --permanent --zone=trusted --remove-source=192.168.1.0/24
sudo firewall-cmd --zone=trusted --list-sources

Add or remove an interface​

Assigns all traffic of an interface to a zone.

sudo firewall-cmd --permanent --zone=internal --add-interface=eth1
sudo firewall-cmd --permanent --zone=internal --remove-interface=eth1
sudo firewall-cmd --zone=internal --change-interface=eth1 # move to another zone
note

A source takes precedence over an interface, so a more specific source can be given different rules than the rest of the traffic on the same interface.

Hostname​

Set​

sudo hostnamectl set-hostname vm7.orgDomain

View​

Use one of the following commands.

hostnamectl status
cat /etc/hostname

HTTP protocol​

Sending arguments​

GET method​

Sent as a query string after the ? in the url.

http://example.com/page?parameter=value&also=another

POST/PUT methods​

Stored as key-value pairs in the body (not visible in the url).

{ "key": "value" }

IP​

Add a route temporarily (until reboot)​

ip route add 192.168.2.1/23 via 10.11.12.3

Add an IP address to an interface temporarily (until reboot)​

sudo ip address add 192.168.1.1/24 dev eth0

Bring interfaces up and down​

sudo ip link set eth0 up
sudo ip link set eth0 down

Delete a route temporarily (until reboot)​

sudo ip route delete 192.168.2.1/23 via 10.11.12.3
sudo ip route delete 192.168.2.1/23 # for all routes to target

Show ARP cache (MAC addresses)​

ip -c neighbor show

Show information for all interfaces​

ip -c link show

Show ip addresses allocated to interfaces​

ip -c address show

Show public ip address​

curl ifconfig.me

Show statistics of an interface​

ip -c -h -s link show eth0
note

Options -c and -h add color and human-readable values to output.

NetworkManager​

Disable IPv6 (GUI)​

In the IPv6 tab of the connection's settings set Method to Disabled.

Ping​

Used to test whether or not a packet can reach a host. Works by sending ICMP echo request (Type 8) packets to the destination host and waits for an ICMP echo reply (Type 0).

The icmp_seq field shows the sequence number of packets sent. If sequence numbers are missing, some connectivity issue is happening and not all packets are getting through. If the sequence number is out of order, the connection is probably very slow as packets are exceeding the one second default.

Useful options​

  • -c X - Stop sending echo request packets after the count has been reached.
  • -I name - Use the specified interface.
  • -4 or -6 - Use only IPv4 or v6.

Route​

Add route temporarily (until reboot)​

sudo route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1
# Add default gateway.
sudo route add default gw 192.168.0.1

Delete route temporarily (until reboot)​

sudo route del -net 192.168.0.0 netmask 255.255.255.0
# Delete default gateway.
sudo route del default

Show routing table​

route

Ss​

Useful options​

OptionDescription
-4IPv4 sockets only.
-aListening and non-listening sockets (established for TCP).
-lListening sockets only.
-mSocket memory usage.
-nDon't resolve numeric adresses/ports.
-oOptions (i.e. state established).
-pProcess using socket.
-tTCP sockets.
-uUDP sockets.
-xUnix domain sockets.
-ZProcess and security context (SELinux).

Traceroute​

See route to target host (how packets are being routed until they get to its final destination).

traceroute targetHost
tip

To bypass firewalls that block ICMP traffic try one of these options: --udp or --tcp

note

The commands on this page were tested on Fedora 40 (unless otherwise specified).