| name | linux-server-mgmt |
| description | Specialized Linux server administration for Ubuntu and RedHat-based systems (RHEL, CentOS, Rocky, AlmaLinux). Use when managing, configuring, troubleshooting, or securing Linux servers including system monitoring, package management, service configuration, user administration, network setup (basic and advanced Layer 1-4 networking with ethtool, VLANs, bonding, bridging, advanced routing, traffic control, iptables/nftables), security hardening, log analysis, performance tuning, backup/restore operations, and automation tasks. |
Linux Server Management
Comprehensive administration toolkit for Ubuntu and RedHat-based Linux servers with battle-tested commands, workflows, and best practices.
Quick Reference
Distribution Detection
Always detect the distribution before running distribution-specific commands:
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
VERSION=$VERSION_ID
fi
if command -v apt &> /dev/null; then
PKG_MGR="apt"
elif command -v dnf &> /dev/null; then
PKG_MGR="dnf"
elif command -v yum &> /dev/null; then
PKG_MGR="yum"
fi
Core Administration Tasks
Package Management
Ubuntu (APT):
sudo apt update
sudo apt upgrade -y
sudo apt full-upgrade -y
sudo apt install <package> -y
sudo apt remove <package>
sudo apt purge <package>
apt search <keyword>
apt show <package>
apt list --installed
sudo apt clean
sudo apt autoclean
sudo apt autoremove
RedHat (DNF/YUM):
sudo dnf check-update
sudo dnf upgrade -y
sudo dnf install <package> -y
sudo dnf remove <package>
dnf search <keyword>
dnf info <package>
dnf list installed
sudo dnf clean all
dnf repolist
Service Management (systemd)
sudo systemctl start <service>
sudo systemctl stop <service>
sudo systemctl restart <service>
sudo systemctl enable <service>
sudo systemctl disable <service>
sudo systemctl status <service>
sudo journalctl -u <service> -f
systemctl list-units --type=service
systemctl --failed
sudo systemctl daemon-reload
User & Group Management
sudo useradd -m -s /bin/bash <username>
sudo passwd <username>
sudo useradd -m -u 1500 -s /bin/bash <username>
sudo userdel <username>
sudo userdel -r <username>
sudo usermod -aG <group> <username>
sudo usermod -s /bin/bash <username>
sudo usermod -L <username>
sudo usermod -U <username>
sudo groupadd <groupname>
sudo groupdel <groupname>
groups <username>
id <username>
finger <username>
File Permissions & Ownership
sudo chown user:group <file>
sudo chown -R user:group <directory>
chmod 755 <file>
chmod -R 644 <directory>
chmod u+s <file>
chmod g+s <file>
chmod +t <dir>
setfacl -d -m u::rwx,g::rx,o::rx <directory>
getfacl <file>
Disk & Filesystem Management
df -h
du -sh /path/to/directory
du -sh * | sort -h
df -i
sudo mount /dev/sdb1 /mnt/data
sudo umount /mnt/data
mount | column -t
findmnt
sudo mkfs.ext4 /dev/sdb1
sudo mkfs.xfs /dev/sdb1
sudo fsck /dev/sdb1
sudo xfs_repair /dev/sdb1
sudo pvcreate /dev/sdb
sudo vgcreate vg_data /dev/sdb
sudo lvcreate -L 10G -n lv_data vg_data
sudo lvextend -L +5G /dev/vg_data/lv_data
sudo resize2fs /dev/vg_data/lv_data
sudo xfs_growfs /mount/point
Network Configuration
Ubuntu (Netplan):
network:
version: 2
ethernets:
eth0:
dhcp4: false
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
sudo netplan apply
sudo netplan try
RedHat (NetworkManager):
nmcli device status
nmcli connection show
nmcli connection up <connection>
nmcli connection down <connection>
sudo nmcli con mod eth0 ipv4.addresses 192.168.1.100/24
sudo nmcli con mod eth0 ipv4.gateway 192.168.1.1
sudo nmcli con mod eth0 ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con mod eth0 ipv4.method manual
sudo nmcli con up eth0
sudo systemctl restart NetworkManager
Common network commands:
ip addr show
ip -4 addr
ip -6 addr
ip route show
ping -c 4 <host>
traceroute <host>
mtr <host>
dig <domain>
nslookup <domain>
host <domain>
ss -tulpn
netstat -tulpn
lsof -i :<port>
sudo iptables -L -n -v
sudo firewall-cmd --list-all
sudo ufw status
Advanced Network Configuration
Layer 1 - Physical Layer Tools
ethtool - NIC configuration and diagnostics:
sudo apt install ethtool -y
sudo dnf install ethtool -y
sudo ethtool eth0
sudo ethtool -i eth0
sudo ethtool -S eth0
sudo ethtool eth0 | grep "Link detected"
sudo ethtool -g eth0
sudo ethtool -k eth0
sudo ethtool -s eth0 speed 1000 duplex full autoneg off
sudo ethtool -K eth0 tx off
sudo ethtool -K eth0 gso off
sudo ethtool -K eth0 tso off
sudo ethtool -s eth0 wol g
sudo ethtool eth0 | grep Wake-on
sudo ethtool -G eth0 rx 4096 tx 4096
sudo ethtool -c eth0
sudo ethtool -C eth0 rx-usecs 50
sudo ethtool -t eth0
mii-tool - Media Independent Interface (older alternative):
mii-tool eth0
sudo mii-tool -F 100baseTx-FD eth0
Layer 2 - Data Link Layer
ARP Management:
ip neigh show
arp -n
sudo ip neigh add 192.168.1.10 lladdr 00:11:22:33:44:55 dev eth0
sudo ip neigh del 192.168.1.10 dev eth0
sudo ip neigh flush all
arping -c 3 -I eth0 192.168.1.10
VLAN Configuration:
sudo apt install vlan -y
sudo dnf install vconfig -y
sudo modprobe 8021q
echo "8021q" | sudo tee -a /etc/modules
sudo ip link add link eth0 name eth0.100 type vlan id 100
sudo ip addr add 192.168.100.1/24 dev eth0.100
sudo ip link set dev eth0.100 up
ip -d link show type vlan
sudo ip link delete eth0.100
network:
version: 2
ethernets:
eth0:
dhcp4: false
vlans:
vlan100:
id: 100
link: eth0
addresses: [192.168.100.1/24]
Bridge Configuration (Layer 2 switching):
sudo apt install bridge-utils -y
sudo dnf install bridge-utils -y
sudo ip link add name br0 type bridge
sudo ip link set eth0 master br0
sudo ip link set eth1 master br0
sudo ip addr add 192.168.1.1/24 dev br0
sudo ip link set eth0 up
sudo ip link set eth1 up
sudo ip link set br0 up
bridge link show
brctl show
sudo ip link set br0 type bridge stp_state 1
bridge -d link show
sudo ip link set eth0 nomaster
sudo ip link delete br0
network:
version: 2
bridges:
br0:
interfaces: [eth0, eth1]
addresses: [192.168.1.1/24]
parameters:
stp: true
forward-delay: 15
Bonding/Teaming (Link Aggregation):
sudo modprobe bonding
echo "bonding" | sudo tee -a /etc/modules
sudo ip link add bond0 type bond mode 802.3ad
sudo ip link set bond0 type bond miimon 100
sudo ip link set bond0 type bond lacp_rate fast
sudo ip link set eth0 master bond0
sudo ip link set eth1 master bond0
sudo ip addr add 192.168.1.1/24 dev bond0
sudo ip link set bond0 up
cat /proc/net/bonding/bond0
network:
version: 2
bonds:
bond0:
interfaces: [eth0, eth1]
addresses: [192.168.1.1/24]
parameters:
mode: 802.3ad
lacp-rate: fast
mii-monitor-interval: 100
sudo nmcli con add type bond ifname bond0 mode 802.3ad
sudo nmcli con add type ethernet ifname eth0 master bond0
sudo nmcli con add type ethernet ifname eth1 master bond0
sudo nmcli con mod bond0 ipv4.addresses 192.168.1.1/24
sudo nmcli con mod bond0 ipv4.method manual
sudo nmcli con up bond0
MAC Address Management:
ip link show eth0 | grep link/ether
sudo ip link set dev eth0 down
sudo ip link set dev eth0 address 00:11:22:33:44:55
sudo ip link set dev eth0 up
network:
version: 2
ethernets:
eth0:
macaddress: 00:11:22:33:44:55
addresses: [192.168.1.10/24]
sudo nmcli con mod eth0 ethernet.cloned-mac-address 00:11:22:33:44:55
Layer 3 - Network Layer
Advanced Routing:
sudo ip route add 10.0.0.0/8 via 192.168.1.254 dev eth0
sudo ip route add default via 192.168.1.1
sudo ip route del 10.0.0.0/8
ip route show
ip route show table all
ip route get 8.8.8.8
sudo ip route add 10.0.0.0/8 via 192.168.1.254 table 100
sudo ip rule add from 192.168.1.0/24 table 100
ip rule show
ip route show table 100
sudo ip route flush table 100
Policy-Based Routing:
sudo ip rule add from 192.168.1.0/24 table 100 priority 100
sudo ip rule add to 10.0.0.0/8 table 100
sudo ip rule add iif eth0 table 100
sudo ip rule add fwmark 1 table 100
sudo ip rule del from 192.168.1.0/24 table 100
IP Tunneling:
sudo ip tunnel add gre1 mode gre remote 203.0.113.2 local 203.0.113.1 ttl 255
sudo ip addr add 10.0.0.1/30 dev gre1
sudo ip link set gre1 up
sudo ip tunnel add ipip1 mode ipip remote 203.0.113.2 local 203.0.113.1
sudo ip addr add 10.0.0.1/30 dev ipip1
sudo ip link set ipip1 up
sudo ip tunnel del gre1
ip tunnel show
Network Namespaces:
sudo ip netns add blue
ip netns list
sudo ip netns exec blue bash
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth1 netns blue
sudo ip netns exec blue ip addr add 10.0.0.1/24 dev veth1
sudo ip netns exec blue ip link set veth1 up
sudo ip netns del blue
IPv6 Configuration:
ip -6 addr show
sudo ip -6 addr add 2001:db8::1/64 dev eth0
ip -6 route show
sudo ip -6 route add 2001:db8:1::/64 via 2001:db8::254
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
ip -6 neigh show
ping6 2001:4860:4860::8888
traceroute6 google.com
Layer 4 - Transport Layer
TCP/UDP Socket Analysis:
ss -a
ss -l
ss -t
ss -ta
ss -tl
ss -u
ss -ua
ss -ul
ss -tp
ss -tlnp
ss -s
ss -tlnp | grep :80
ss state established
ss state time-wait
ss state syn-sent
ss dst 192.168.1.10
ss src 192.168.1.0/24
ss -e
ss -m
ss -i
netstat (legacy but still useful):
netstat -a
netstat -l
netstat -p
netstat -n
netstat -c
netstat -r
netstat -i
netstat -s
Traffic Control (tc) - QoS and Bandwidth Management:
tc qdisc show
sudo tc qdisc add dev eth0 root tbf rate 1mbit burst 32kbit latency 400ms
sudo tc qdisc del dev eth0 root
sudo tc qdisc add dev eth0 root handle 1: htb default 30
sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit
sudo tc class add dev eth0 parent 1:1 classid 1:10 htb rate 50mbit ceil 100mbit
sudo tc class add dev eth0 parent 1:1 classid 1:20 htb rate 30mbit ceil 100mbit
sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 \
match ip dst 192.168.1.10/32 flowid 1:10
tc -s class show dev eth0
sudo tc qdisc add dev eth0 root netem delay 100ms
sudo tc qdisc add dev eth0 root netem loss 1%
sudo tc qdisc add dev eth0 root netem delay 100ms 10ms
sudo tc qdisc add dev eth0 root netem delay 100ms 10ms loss 1% reorder 25% 50%
sudo apt install wondershaper -y
sudo wondershaper -a eth0 -d 1024 -u 512
sudo wondershaper -c -a eth0
Connection Tracking (conntrack):
sudo apt install conntrack -y
sudo dnf install conntrack-tools -y
sudo conntrack -L
sudo conntrack -L -p tcp
sudo conntrack -L -p udp
sudo conntrack -C
sudo conntrack -S
sudo conntrack -D -p tcp --orig-port-dst 80
sudo conntrack -F
iptables - Advanced Packet Filtering:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 192.168.1.10:80
sudo iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 203.0.113.1
sudo iptables -t mangle -A PREROUTING -p tcp --dport 80 -j MARK --set-mark 1
sudo iptables -t nat -L -n -v
sudo iptables -t mangle -L -n -v
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -m limit --limit 3/min -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -m recent --set --name SSH
sudo iptables -A INPUT -p tcp --dport 22 -m recent --update --seconds 60 --hitcount 4 --name SSH -j DROP
nftables (modern replacement for iptables):
sudo apt install nftables -y
sudo dnf install nftables -y
sudo nft list ruleset
sudo nft add table inet filter
sudo nft add chain inet filter input { type filter hook input priority 0 \; }
sudo nft add rule inet filter input tcp dport 22 accept
sudo nft add table nat
sudo nft add chain nat postrouting { type nat hook postrouting priority 100 \; }
sudo nft add rule nat postrouting masquerade
sudo nft list ruleset > /etc/nftables.conf
sudo nft flush ruleset
Advanced Network Diagnostics:
sudo tcpdump -i eth0
sudo tcpdump -i eth0 port 80
sudo tcpdump -i eth0 host 192.168.1.10
sudo tcpdump -i eth0 -w capture.pcap
sudo tcpdump -i eth0 -c 100
sudo apt install tshark -y
sudo tshark -i eth0
sudo tshark -i eth0 -f "port 80"
sudo apt install ngrep -y
sudo ngrep -d eth0 'HTTP' port 80
sudo apt install iftop -y
sudo iftop -i eth0
sudo apt install nethogs -y
sudo nethogs eth0
sudo apt install iperf3 -y
iperf3 -s
iperf3 -c server_ip
sudo apt install nload -y
nload eth0
sudo apt install bmon -y
bmon
Network Performance Tuning:
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
net.core.rmem_default = 65536
net.core.wmem_default = 65536
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
net.ipv4.tcp_congestion_control = bbr
net.core.default_qdisc = fq
net.ipv4.tcp_mtu_probing = 1
sudo sysctl -p
echo "tcp_bbr" | sudo tee -a /etc/modules-load.d/modules.conf
sudo modprobe tcp_bbr
Firewall Management
Ubuntu (UFW):
sudo ufw enable
sudo ufw disable
sudo ufw allow 22/tcp
sudo ufw allow from 192.168.1.0/24 to any port 22
sudo ufw deny 80/tcp
sudo ufw delete allow 80/tcp
sudo ufw status verbose
sudo ufw status numbered
sudo ufw reset
RedHat (firewalld):
sudo systemctl enable --now firewalld
sudo systemctl stop firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --remove-service=http
sudo firewall-cmd --reload
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --permanent --remove-port=8080/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
sudo firewall-cmd --list-services
sudo firewall-cmd --list-ports
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --zone=public --list-all
System Monitoring
top
htop
vmstat 1
mpstat -P ALL 1
free -h
cat /proc/meminfo
iostat -x 1
iotop
iftop
nethogs
nload
ps aux
ps -ef
pstree
pgrep <process>
uptime
w
who
last
lastlog
Log Analysis
sudo journalctl -xe
sudo journalctl -u <service>
sudo journalctl --since "1 hour ago"
sudo journalctl -f
sudo tail -f /var/log/syslog
sudo tail -f /var/log/messages
sudo tail -f /var/log/auth.log
sudo tail -f /var/log/secure
sudo tail -f /var/log/apache2/error.log
sudo tail -f /var/log/httpd/error_log
sudo tail -f /var/log/nginx/error.log
sudo grep -i "error" /var/log/syslog
sudo journalctl | grep -i "failed"
logrotate -d /etc/logrotate.conf
Security Hardening
SSH Hardening:
sudo vim /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
X11Forwarding no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
Protocol 2
sudo systemctl restart sshd
Automatic Updates:
Ubuntu:
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure -plow unattended-upgrades
RedHat:
sudo dnf install dnf-automatic -y
apply_updates = yes
sudo systemctl enable --now dnf-automatic.timer
SELinux (RedHat):
sestatus
getenforce
sudo setenforce 0
sudo setenforce 1
SELINUX=enforcing
sudo ausearch -m avc -ts recent
sudo audit2why < /var/log/audit/audit.log
sudo audit2allow -a
AppArmor (Ubuntu):
sudo aa-status
sudo aa-enforce /etc/apparmor.d/<profile>
sudo aa-complain /etc/apparmor.d/<profile>
sudo aa-disable /etc/apparmor.d/<profile>
sudo systemctl reload apparmor
Performance Tuning
Kernel Parameters:
sysctl -a
sysctl vm.swappiness
sudo sysctl -w vm.swappiness=10
vm.swappiness=10
net.core.rmem_max=134217728
net.core.wmem_max=134217728
sudo sysctl -p
Swap Management:
swapon --show
free -h
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
/swapfile none swap sw 0 0
sudo swapoff /swapfile
sudo rm /swapfile
Backup & Restore
Using tar:
sudo tar -czf backup-$(date +%Y%m%d).tar.gz /path/to/data
sudo tar -xzf backup.tar.gz -C /restore/location
sudo tar -czf backup.tar.gz --listed-incremental=snapshot.file /data
Using rsync:
sudo rsync -avz --delete /source/ /backup/
sudo rsync -avz -e ssh /source/ user@remote:/backup/
sudo rsync -avz --exclude='*.log' --exclude='cache/' /source/ /backup/
System backup (full):
sudo tar -czpf /backup/system-$(date +%Y%m%d).tar.gz \
--exclude=/backup \
--exclude=/proc \
--exclude=/sys \
--exclude=/dev \
--exclude=/run \
--exclude=/tmp \
--exclude=/mnt \
--exclude=/media \
/
Cron Jobs & Scheduling
crontab -e
sudo crontab -e
crontab -l
sudo crontab -l
0 2 * * * /path/to/backup.sh
*/15 * * * * /path/to/monitor.sh
0 0 * * 0 /path/to/weekly.sh
0 3 1 * * /path/to/monthly.sh
/etc/cron.daily/
/etc/cron.weekly/
/etc/cron.monthly/
sudo systemctl list-timers
Troubleshooting Workflows
System Won't Boot
- Boot into recovery/rescue mode
- Check recent changes:
sudo journalctl -xb -1
- Verify filesystem:
sudo fsck -y /dev/sda1
- Check fstab:
cat /etc/fstab
- Review boot logs:
dmesg | less
- Check GRUB configuration:
/etc/default/grub
High CPU Usage
- Identify process:
top or htop
- Details:
ps aux | grep <PID>
- Thread view:
top -H -p <PID>
- Check logs:
sudo journalctl -u <service>
- Strace process:
sudo strace -p <PID>
High Memory Usage
- Check usage:
free -h
- Top consumers:
ps aux --sort=-%mem | head
- Details per process:
pmap <PID>
- Check for memory leaks:
valgrind <command>
- Review swap usage:
vmstat 1
Disk Full
- Check usage:
df -h
- Find large files:
sudo du -h / | sort -h | tail -20
- Find large directories:
sudo du -sh /* | sort -h
- Clean package cache:
sudo apt clean or sudo dnf clean all
- Clean logs:
sudo journalctl --vacuum-size=100M
- Find old files:
find /var/log -type f -mtime +30
Network Issues
- Check interface:
ip addr show
- Check routing:
ip route show
- Test connectivity:
ping -c 4 8.8.8.8
- DNS test:
dig google.com
- Check firewall:
sudo iptables -L -n or sudo ufw status
- Review network logs:
sudo journalctl -u NetworkManager
Service Won't Start
- Check status:
sudo systemctl status <service>
- View logs:
sudo journalctl -u <service> -n 50
- Check config syntax: Depends on service (e.g.,
nginx -t)
- Verify permissions:
ls -la /etc/<service>/
- Check dependencies:
systemctl list-dependencies <service>
- Test manually: Run service binary with debug flags
Best Practices
- Always backup before making changes - Create snapshots or backups of critical configurations
- Use sudo appropriately - Don't run as root unnecessarily; use sudo for specific commands
- Document changes - Keep notes of configuration modifications in
/root/CHANGES.log or similar
- Test in non-production first - Validate commands on test systems when possible
- Check logs after changes - Always verify service logs after configuration changes
- Use version control for configs - Track important configurations in git
- Keep systems updated - Regularly apply security patches
- Monitor disk space - Set up alerts for disk usage thresholds
- Use appropriate file permissions - Follow principle of least privilege
- Enable firewall - Always run a firewall with minimal required ports open
Common Pitfalls
General Administration
- Not checking distribution before running package manager commands
- Forgetting to reload/restart services after configuration changes
- Not backing up configuration files before editing
- Using
rm -rf without double-checking the path
- Modifying SELinux/AppArmor without understanding implications
- Assuming commands work identically across distributions
- Neglecting to check logs after making changes
Networking Specific
- Not testing firewall rules before disconnecting from remote session (lock yourself out)
- Changing network config on remote server without console access backup
- Applying tc (traffic control) rules on production without testing (can severely impact performance)
- Flushing iptables/nftables rules without saving first
- Enabling IP forwarding without proper firewall rules (creates open relay)
- Modifying MTU without understanding path MTU discovery implications
- Setting wrong VLAN ID or not trunking VLAN on switch side
- Forgetting to bring interfaces up after configuration changes
- Not testing bonding/teaming configuration before removing physical connections
- Misconfiguring bridge and losing network connectivity
- Using ethtool to force speed/duplex without matching switch config
- Applying network namespaces commands to wrong namespace
- Not saving iptables rules (lost on reboot unless configured)
- Setting up NAT without enabling IP forwarding in kernel
- Changing MAC address on interface with static DHCP reservation
- Testing network changes during business hours without maintenance window
- Not documenting custom routing tables and policy routing rules
Reference Files
For more specialized topics, see the bundled reference files:
references/apache-nginx.md - Web server configuration and troubleshooting
references/database.md - MySQL/PostgreSQL administration
references/containers.md - Docker and Podman management
references/monitoring.md - Advanced monitoring and alerting setup
references/advanced-networking.md - Deep-dive Layer 1-4 networking scenarios, SR-IOV, VRF, VXLAN, traffic shaping, and production troubleshooting