- ahao3582018-06-08金牌会员50392
多IP服务器通过NAT共享网络
以下配置实现3个外网IP 11.11.11.11、22.22.22.22、33.33.33.33分别通过不同的内网网段 192.168.X.1 进行共享网络。auto lo
iface lo inet loopbackauto eth0
iface eth0 inet static
address 11.11.11.11
netmask 255.255.255.0
gateway 11.11.11.1auto eth0:1
iface eth0:1 inet static
address 22.22.22.22
netmask 255.255.255.0
gateway 22.22.22.1auto eth0:2
iface eth0:2 inet static
address 33.33.33.33
netmask 255.255.255.0
gateway 33.33.33.1auto vmbr0
#private sub network
iface vmbr0 inet static
address 192.168.0.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 11.11.11.11
post-down iptables -t nat -D POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 11.11.11.11auto vmbr1
#private sub network
iface vmbr1 inet static
address 192.168.1.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 22.22.22.22
post-down iptables -t nat -D POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 22.22.22.22auto vmbr2
#private sub network
iface vmbr2 inet static
address 192.168.2.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 33.33.33.33
post-down iptables -t nat -D POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 33.33.33.33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
auto lo
iface lo inet loopbackauto eth0
iface eth0 inet static
address 11.11.11.11
netmask 255.255.255.0
gateway 11.11.11.1auto eth0:1
iface eth0:1 inet static
address 22.22.22.22
netmask 255.255.255.0
gateway 22.22.22.1auto eth0:2
iface eth0:2 inet static
address 33.33.33.33
netmask 255.255.255.0
gateway 33.33.33.1auto vmbr0
#private sub network
iface vmbr0 inet static
address 192.168.0.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 11.11.11.11
post-down iptables -t nat -D POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 11.11.11.11auto vmbr1
#private sub network
iface vmbr1 inet static
address 192.168.1.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 22.22.22.22
post-down iptables -t nat -D POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 22.22.22.22auto vmbr2
#private sub network
iface vmbr2 inet static
address 192.168.2.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 33.33.33.33
post-down iptables -t nat -D POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 33.33.33.33多单网卡多IP共享给小鸡的,具体请看:https://www.ahao.me/archives/1136