NAT模式

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 实现均衡负载

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值