NAT模式
[root@server4 ~]# ip addr add 192.168.2.1/24 dev eth1
[root@server4 ~]# ip link set up eth1
[root@server4 ~]# ip addr
2: eth0:
link/ether 52:54:00:f5:49:4b brd ff:ff:ff:ff:ff:ff
inet 172.25.77.4/24 brd 172.25.77.255 scope global eth0
3: eth1:
link/ether 52:54:00:46:55:60 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.1/24 scope global eth1
[root@server4 ~]# sysctl -a |grep ip_forward
net.ipv4.ip_forward = 0
[root@server4 ~]# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1
[root@server4 ~]# ll /etc/sysctl.conf
-rw-r--r--. 1 root root 1150 10月 10 2013 /etc/sysctl.conf
[root@server4 ~]# sysctl -a |grep ip_forward
net.ipv4.ip_forward = 1
[root@server4 ~]# /etc/init.d/ipvsadm start
[root@server4 ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@server4 ~]# ipvsadm -A -t 192.168.2.1:80 -s rr
[root@server4 ~]# ipvsadm -a -t 192.168.2.1:80 -r 172.25.77.2:80 -m
[root@server4 ~]# ipvsadm -a -t 192.168.2.1:80 -r 172.25.77.3:80 -m
[root@server4 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.2.1:80 rr
-> 172.25.77.2:80 Masq 1 0 0
-> 172.25.77.3:80 Masq 1 0 0
Server2
Server3
添加server4的ip作为网关
[root@server2 ~]# route add default gw 172.25.77.4
[root@server2 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.77.2 for ServerName
[ OK ]
[root@server2 ~]# ping 172.25.77.4
PING 172.25.77.4 (172.25.77.4) 56(84) bytes of data.
64 bytes from 172.25.77.4: icmp_seq=1 ttl=64 time=0.733 ms
64 bytes from 172.25.77.4: icmp_seq=2 ttl=64 time=0.190 ms
[root@server3 ~]# route add default gw 172.25.77.4
[root@server3 ~]# /etc/init.d/httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for server3
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
客户端实验结果
客户端添加和server4同网段ip
[root@foundation77 ~]# ip addr add 192.168.2.2/24 dev br0
[root@foundation77 ~]# curl 192.168.2.1
www.westos.org - server 3
[root@foundation77 ~]# curl 192.168.2.1
www.westos.org - server2
[root@foundation77 ~]# curl 192.168.2.1
www.westos.org - server 3
[root@foundation77 ~]# curl 192.168.2.1
www.westos.org - server2
Server2 server3 添加server4的ip作为网关
客户端添加和server4同网段的ip
Server4设置eth1 eth0 设置两个ip
Server4 和 server2 server3 不在同一个vlan也可以通过server4 实现均衡负载