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高可用方案
虚拟IP(VIP)是实现服务高可用的核心技术,当主服务器故障时,VIP会自动漂移到备用节点,保证服务不间断。
配置步骤详解:
- 安装keepalived:
apt-get install keepalived -y- 主节点配置(/etc/keepalived/keepalived.conf):
vrrp_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)可提升带宽和可靠性,凝思系统支持多种绑定模式:
| 模式编号 | 模式名称 | 特点 | 适用场景 |
|---|---|---|---|
| mode=0 | 轮询模式 | 均衡负载 | 高带宽需求 |
| mode=1 | 主备模式 | 故障自动切换 | 高可用需求 |
| mode=4 | 动态链路聚合 | 需要交换机支持LACP | 企业级网络环境 |
配置实例(mode=4):
auto 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