1 问题表现
SNAT 下,使用 keepalived 做双机热备,会出现了 ip 冲突的 问题。
2 网络拓扑
2.1 主机 FW1 的配置:
2.1.1 主机的 iptables 配置
将所有 192.168.8.0/24,地址转换为出口 ip 10.10.10.254。
iptables -t nat -A POSTROUTING -s 192.168.8.0/24 -j SNAT --to-source 10.10.10.254
2.1.2 主机的 keepalived.conf 配置
vrrp_group | mcast_src_ip |
虚拟 ip |
---|---|---|
VI_1 | 10.101.101.1/24 | 10.10.10.254/24 |
VI_2 | 192.168.8.1/24 | 192.168.8.254/24 |
! Configuration File for keepalived
global_defs {
vrrp_sync_group G1{
group{
VI_1
VI_2
}
}
router_id localhost.localdomain
}
vrrp_instance VI_1 {
state BACKUP
interface vEth0
track_interface {
vEth0
vEth1
}
mcast_src_ip 10.101.101.1
virtual_router_id 10
priority 200
advert_int 3
virtual_ipaddress {
10.10.10.254/24
}
}
vrrp_instance VI_2 {
state BACKUP
interface vEth1
track_interface {
vEth0
vEth1
}
mcast_src_ip 192.168.8.1
virtual_router_id 20
priority 200
advert_int 3
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.8.254/24
}
}