简介:本文详细解析服务器双网卡双IP双网关配置的全流程,涵盖物理连接、系统配置、路由规则及故障排查,提供Linux/Windows双系统操作指南与实用脚本,助力实现网络冗余、流量隔离及安全加固。
在数据中心和企业网络环境中,双网卡双IP双网关架构通过物理隔离或逻辑隔离实现三大核心价值:
推荐采用”主备+负载”混合模式:
关键设计原则:
修改/etc/netplan/01-netcfg.yaml:
network:version: 2renderer: networkdethernets:eth0:dhcp4: noaddresses: [192.168.1.10/24]gateway4: 192.168.1.1nameservers:addresses: [8.8.8.8, 1.1.1.1]eth1:dhcp4: noaddresses: [10.0.0.10/24]gateway4: 10.0.0.1routes:- to: 172.16.0.0/16via: 10.0.0.254
创建路由表文件/etc/iproute2/rt_tables:
100 mgmt_table200 business_table
添加路由规则:
# 管理网路由ip route add 192.168.1.0/24 dev eth0 src 192.168.1.10 table mgmt_tableip route add default via 192.168.1.1 dev eth0 table mgmt_table# 业务网路由ip route add 10.0.0.0/24 dev eth1 src 10.0.0.10 table business_tableip route add default via 10.0.0.1 dev eth1 table business_table# 策略规则ip rule add from 192.168.1.10 table mgmt_tableip rule add from 10.0.0.10 table business_table
使用route add命令或通过图形界面:
route -p add 10.0.0.0 mask 255.255.255.0 10.0.0.1 metric 1 if <接口编号>
netsh配置更复杂的策略路由:
netsh interface ipv4 add route 172.16.0.0/16 "业务网" 10.0.0.254
# Linux测试命令ping -c 4 192.168.1.1 # 管理网关ping -c 4 10.0.0.1 # 业务网关traceroute 8.8.8.8 # 检查路由路径# Windows测试命令tracert 8.8.8.8test-netconnection 192.168.1.1
路由冲突:
ip route show检查默认路由,删除冲突条目ARP缓存错误:
ip -s neigh flush all(Linux)或arp -d(Windows)网卡驱动问题:
ethtool -k eth0检查卸载功能使用keepalived实现双网卡VIP:
vrrp_script chk_httpd {script "killall -0 httpd"interval 2weight 2}vrrp_instance VI_1 {interface eth0state MASTERvirtual_router_id 51priority 100virtual_ipaddress {192.168.1.100}track_script {chk_httpd}}
iptables -A INPUT -i eth0 -p tcp --dport 22 -s 192.168.1.0/24 -j ACCEPTiptables -A INPUT -i eth0 -j DROP
监控指标:
ethtool -S eth0)watch -n 1 ip route)ip neigh show)备份策略:
/etc/network/interfaces(Debian系)变更管理:
通过以上系统化的配置与维护,可构建出高可用、安全的双网卡网络架构。实际部署时建议先在测试环境验证,再逐步迁移至生产环境,同时建立完善的监控告警机制,确保网络稳定运行。