Linux 教程(47):网络配置与管理

网络基础

Linux 网络配置是系统管理员的必备技能。

IP 地址配置

临时配置

ip addr add 192.168.1.100/24 dev eth0
ip addr del 192.168.1.100/24 dev eth0

永久配置 (Ubuntu)

# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    eth0:
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

DNS 配置

# /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

防火墙配置

ufw (Ubuntu)

ufw enable
ufw disable
ufw status
ufw allow 22/tcp
ufw deny 80/tcp

firewalld (CentOS)

firewall-cmd --state
firewall-cmd --add-service=ssh
firewall-cmd --add-port=80/tcp

SSH 配置

# /etc/ssh/sshd_config
Port 22
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

网络诊断

ping host          # 测试连通性
traceroute host    # 跟踪路由
mtr host           # 增强 traceroute
dig domain         # DNS 查询
nslookup domain    # DNS 查询

网络服务

systemctl restart networking
systemctl restart NetworkManager
netplan apply

网络配置,畅通无阻!

发表回复

后才能评论