Lesson 04 - chad-p/wiki-linux-class GitHub Wiki

Networking and System Management

Ping and Jobs

ping 8.8.8.8
# ctrl z (send process to background)

ps
jobs -l
fg 1

kill -l
kill -9 <pid>

fg
# ctrl c

ping -c 4 8.8.8.8

Traceroute

  • tracert(windows) will use ICMP echo requests.
  • traceroute(linux) defaults to UDP echo requests.
traceroute google.com
mtr google.com

IP

# These are all the same
ip a
ip addr
ip address
ip address show

ip link
ip route
ip neigh  # ARP
sudo ip address add 192.168.121.45/24 dev enp0s3
sudo ip address del 192.168.121.45/24 dev enp0s3

ip route get 1.1.1.1
ip link set enp0s3 down

Dhclient

cd /etc/dhcp
dhclient 

Setting Static IP

Route

man route # Checkout flags
route

sudo ip route add 192.168.121.0/24 dev enp0s3
sudo ip route del 192.168.121.0/24

DNS

nslookup example.com 8.8.8.8
watch !!  # Will rerun the last command ever few seconds. Good for waiting for DNS up propagate.

# Replacement for nslookup
dig example.com

# Resolved
cat /etc/resolve.conf
ll /etc/resolve.conf
sudo systemctl status systemd-resolved
systemd-resolve --status
cat /etc/systemd/resolved.conf

# Hosts file
cat /etc/hosts

Netstat and SS

# see established connections on specified port
ss -n -o state established '( dport = :21 or sport = :21 )'

# List all connections
ss -a 
# List listening sockets
ss -l 

netstat
netstat -naob
# What is running on port 80
netstat -tulpn | grep 80

lsof

lsof -u <user>
lsof -i # all network connections
lsof -i :80

apt and dpkg

apt update
apt upgrade
apt search nmap
apt install nmap apache2
apt remove nmap
apt purge nmap

/var/log/apt/history.log  # Find apt history

apt list
apt list --installed

apt show apache2

#####
dpkg --help
dpkg -l
wget http://archive.ubuntu.com/ubuntu/pool/universe/c/cowsay/cowsay_3.03+dfsg2-4_all.deb
dpkg -c cowsay*
dpkg -I <package.deb>  #Info
dpkg -i <package.deb>  #Install

yum and rpm

yum history
yum updateinfo
yum updateinfo list
yum updateinfo list --sec-severity=Critical

man yum-secuirty
yum update --security

# Signed Packages
rpm --import /tmp/<some key>
rpm -qa gpg-pubkey*
rpm -qi <key>

# Download a package then verify key
rpm -K *.rpm

# Install local package
yum localinstall <package>
rpm -i <package>  # or with rpm
rpm -e <package>  # remove

# Search with RPM
rpm --help
rpm -q cowsay
rpm -ql cowsay  # List all files from that package
rpm -qi cowsay  # Package summary

Services | Daemons

# Service is SysV
server --status-all
service sshd status
cat /etc/initab

# Systemctl
systemctl list-units
systemctl list-units --type service --state running
systemctl list-units --type service --state running --no-legend
systemctl list-units --type service --state failed --no-legend
systemctl --no-pager | grep service | grep running | column -t
systemd-analyze blame

systemctl status sshd
systemctl start sshd
systemctl enable sshd
systemctl disable sshd
#Disable services for hardening

cat /usr/lib/systemd/system/sshd.service
systmctl cat sshd
systemctl daemon-reload
systemctl --no-pager show --property=UnitPath

Journald

# follow the ssh service
journalctl -u ssh -f

dmesg

dmesg -H

nginx

cd /etc/nginx/sites-enabled/default
⚠️ **GitHub.com Fallback** ⚠️