![IPIP 隧道用于 Ubuntu 中的负载平衡](https://linux22.com/image/518941/IPIP%20%E9%9A%A7%E9%81%93%E7%94%A8%E4%BA%8E%20Ubuntu%20%E4%B8%AD%E7%9A%84%E8%B4%9F%E8%BD%BD%E5%B9%B3%E8%A1%A1.png)
我在 gentoo 负载平衡器和 gentoo real 服务器之间设置了 ldirectord/heartbeat HA。由于主机的限制,我通过 ipip 隧道进行负载平衡。
我在gentoo real服务器上有以下设置:
(附加到...末尾)/etc/conf.d/net
iptunnel_tunl0="mode ipip"
config_tunl0=(
"xxx.xxx.xxx.xxx netmask 255.255.255.255"
"yyy.yyy.yyy.yyy netmask 255.255.255.255"
"zzz.zzz.zzz.zzz netmask 255.255.255.255"
)
那些 xxx/yyy/zzz ips 是我的共享 ip 地址。
“ip address show” 显示如下结果:
4: tunl0: <NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN
link/ipip 0.0.0.0 brd 0.0.0.0
inet xxx.xxx.xxx.xxx/32 scope global tunl0
inet yyy.yyy.yyy.yyy/32 scope global tunl0:1
inet zzz.zzz.zzz.zzz/32 scope global tunl0:2
一切都运行良好。
我现在正尝试设置 ipip 隧道到 Ubuntu 真实服务器。
我可以使用以下命令显示界面:
ip tunnel add tunl0 mode ipip
然后将 IP 地址附加到 /etc/network/interfaces
auto tunl0
iface tunl0 inet static
address xxx.xxx.xxx.xxx
netmask 255.255.255.255
然后我的“ip addr show”命令显示与 gentoo 机器上相同的内容
问题是 ip tunnel add.. 在重启后不会保留,因此下次尝试加载网络时,我们会收到此信息
# /etc/init.d/networking restart
* Reconfiguring network interfaces...
ssh stop/waiting
ssh start/running, process 2442
ssh stop/waiting
ssh start/running, process 2482
SIOCSIFADDR: No such device
tunl0: ERROR while getting interface flags: No such device
SIOCSIFNETMASK: No such device
tunl0: ERROR while getting interface flags: No such device
Failed to bring up tunl0.
...done.
我怎样才能使隧道接口以与 Gentoo 中相同的方式持续存在?
答案1
有两种方法可以解决这个问题。如果您只需要一个简单的命令,最简单的方法是在 /etc/network/interfaces 中的条目中添加pre-up
和行:pre-down
auto tunl0
iface tunl0 inet static
pre-up ip tunnel add tunl0 mode ipip
post-down ip tunnel del tunl0 mode ipip
address xxx.xxx.xxx.xxx
netmask 255.255.255.255
或者,如果您想做更复杂的事情,您可以分别添加在启动网络之前和关闭网络之后运行的/etc/network/if-pre-up.d/
脚本。/etc/network/if-post-down.d/
答案2
五年来,事情已经取得了长足的进步。这些行属于(/etc/network/interfaces)
请参阅man 5 intefaces
此处了解更多详情。
# Choose your own name for your tunnel interface (example uses 'mytun')
auto mytun
iface mytun inet tunnel
mode ipip
# Best I can tell, value of 'netmask' does nothing but is required:
netmask 255.255.255.255
# Local address (inside tunnel) (required)
address 192.168.1.1
# dstaddr = remote address (inside tunnel)
dstaddr 192.168.2.2
# local = address of tunnel interface
local x.x.x.x
# endpoint = destination ip applied to ipip encapsulated packets (required)
endpoint y.y.y.y
# You may want to also consider using these two options
# mtu 1480
# ttl 63