# ifconfig (已逐渐被淘汰)
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
# route
route add default gw 192.168.1.1
# 网络服务控制
service network restart # RHEL/CentOS 6
/etc/init.d/networking restart # Debian/Ubuntu
# 查看所有接口
ip link show
# 配置IP地址
ip addr add 192.168.1.100/24 dev eth0
# 设置默认网关
ip route add default via 192.168.1.1
# 查看路由表
ip route show
# 基本命令
nmcli device status
nmcli connection show
# 配置静态IP
nmcli con add con-name "static-eth0" ifname eth0 type ethernet ip4 192.168.1.100/24 gw4 192.168.1.1
/etc/network/interfaces
:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
/etc/sysconfig/network-scripts/ifcfg-eth0
:
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
/etc/resolv.conf
:
nameserver 8.8.8.8
nameserver 8.8.4.4
# 安装必要工具(RHEL/CentOS)
yum install -y teamd
# 创建绑定接口
nmcli con add type team con-name team0 ifname team0 config '{"runner": {"name": "activebackup"}}'
# 添加从属接口
nmcli con add type team-slave con-name team0-port1 ifname eth0 master team0
nmcli con add type team-slave con-name team0-port2 ifname eth1 master team0
# 创建桥接接口
brctl addbr br0
brctl addif br0 eth0
# 使用iproute2创建桥接
ip link add name br0 type bridge
ip link set eth0 master br0
# 创建VLAN接口
ip link add link eth0 name eth0.100 type vlan id 100
# 配置VLAN IP
ip addr add 192.168.100.1/24 dev eth0.100
# 测试连通性
ping 8.8.8.8
# 跟踪路由路径
traceroute google.com
tracepath google.com
# 网络扫描
nmap -sP 192.168.1.0/24
# DNS查询
dig google.com
nslookup google.com
# 网络流量分析
tcpdump -i eth0 -n
# 带宽测试
iperf3 -s # 服务器端
iperf3 -c server_ip # 客户端
# 网络统计
ss -tulnp # 查看监听端口
netstat -s # 网络统计信息
# 允许SSH访问
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 默认策略
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# 保存规则(RHEL/CentOS)
service iptables save
# 基本命令
firewall-cmd --state
firewall-cmd --list-all
# 开放端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
网络接口不工作
ip link show
查看接口状态ethtool eth0
检查网卡参数无法访问外部网络
ip route show
dig google.com
网络速度慢
ethtool
检查双工模式和速度iperf3
测试带宽ip -s link show eth0
服务无法访问
ss -tulnp | grep service_port
getenforce
通过掌握这些网络拓扑结构和配置方法,您将能够有效地在Linux系统中设置和管理各种网络环境。