凝思操作系统网络配置进阶:静态IP、虚拟IP与多网卡绑定实战 📅 2026/7/14 18:50:25 1. 静态IP配置实战单网卡多地址方案在企业服务器部署中经常需要为单块物理网卡配置多个IP地址。这种方案通常用于实现网络隔离或服务分离比如在同一台服务器上同时运行测试环境和生产环境服务。配置文件实操打开/etc/network/interfaces文件基础配置如下auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1添加IP别名auto eth0:1 iface eth0:1 inet static address 192.168.1.101 netmask 255.255.255.0关键注意事项每个IP别名需要独立的配置段如eth0:1、eth0:2主IP必须配置网关而别名IP通常不需要使用allow-hotplug参数确保热插拔时网络自动恢复验证命令ifconfig -a | grep eth0 ip addr show eth0实际案例某金融系统需要同时连接内网数据库和外网API通过单网卡双IP方案主IP 10.0.0.100连接内网不设网关别名IP 172.16.0.100连接外网配置网关2. 虚拟IP高可用方案虚拟IPVIP是实现服务高可用的核心技术当主服务器故障时VIP会自动漂移到备用节点保证服务不间断。配置步骤详解安装keepalivedapt-get install keepalived -y主节点配置/etc/keepalived/keepalived.confvrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.200/24 } }备用节点配置vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.200/24 } }健康检查方案virtual_server 192.168.1.200 80 { delay_loop 6 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.1.100 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }典型故障排查检查VRRP报文是否被防火墙拦截确认virtual_router_id在所有节点一致使用tcpdump抓包分析tcpdump -i eth0 vrrp -n3. 多网卡绑定与负载均衡多网卡绑定bonding可提升带宽和可靠性凝思系统支持多种绑定模式模式编号模式名称特点适用场景mode0轮询模式均衡负载高带宽需求mode1主备模式故障自动切换高可用需求mode4动态链路聚合需要交换机支持LACP企业级网络环境配置实例mode4auto bond0 iface bond0 inet static address 10.0.0.100 netmask 255.255.255.0 gateway 10.0.0.1 bond-mode 4 bond-miimon 100 bond-lacp-rate 1 bond-slaves eth0 eth1性能调优参数bond-miimon链路检测间隔毫秒bond-downdelay下线延迟时间bond-updelay上线延迟时间实际部署经验先确认交换机配置# Cisco交换机 interface Port-channel1 switchport trunk encapsulation dot1q switchport mode trunk ! interface GigabitEthernet0/1 channel-group 1 mode active测试故障转移# 模拟链路故障 ifconfig eth1 down # 观察流量切换 cat /proc/net/bonding/bond04. 网络隔离与安全加固VLAN隔离方案auto eth0.100 iface eth0.100 inet static address 192.168.100.100 netmask 255.255.255.0 vlan-raw-device eth0防火墙策略建议# 仅允许VIP访问管理端口 iptables -A INPUT -p tcp --dport 22 -s 192.168.1.200 -j ACCEPT iptables -A INPUT -p tcp --dport 22 -j DROP # 保护VRRP通信 iptables -I INPUT -p vrrp -j ACCEPT系统参数优化# 禁用IP转发非网关设备 echo 0 /proc/sys/net/ipv4/ip_forward # 开启SYN Cookie防护 echo 1 /proc/sys/net/ipv4/tcp_syncookies网络诊断工具箱连通性测试mtr -n 8.8.8.8带宽测试iperf3 -c 192.168.1.1抓包分析tcpdump -i bond0 -w capture.pcap路由检查ip route show table all