添加虚拟接口到Ubuntu的脚本

任何人都知道一个脚本或命令将所有需要的信息添加到/ etc / interfaces来添加一个新的虚拟接口?

这将需要添加一个新的:

iface eth0:4 inet static address xyxy netmask 255.255.240.0 

并更新主networking接口。

 auto eth0 eth0:1 eth0:2 eth0:3 eth0:4 

 #!/bin/sh # Usage: addif alias_nic address netmask cat >>/etc/network/interfaces <<EOF auto $1 iface $1 inet static address $2 netmask $3 EOF ifup $1 

我通常在接口文件中做这样的事情来绑定其他地址与接口。 我使用up / down来执行作为iproute包的一部分的外部ip命令。

 auto eth0 iface eth0 inet static address 192.168.32.10 netmask 255.255.255.0 network 192.168.32.0 broadcast 192.168.32.255 gateway 192.168.32.1 # bind .25 for bar up ip addr add 192.168.32.25/24 brd + dev eth0 down ip addr del 192.168.32.25/24 brd + dev eth0 # bind .47 for foo up ip addr add 192.168.32.47/24 brd + dev eth0 down ip addr del 192.168.32.47/24 brd + dev eth0 

当然,把这样的东西放在你的interfaces文件中也是合法的,尽pipe我有点像前者更好。

 auto eth0 iface eth0 inet static address 192.168.32.10 netmask 255.255.255.0 network 192.168.32.0 broadcast 192.168.32.255 gateway 192.168.32.1 auto eth0:1 iface eth0:1 inet static address 192.168.32.25 netmask 255.255.255.0 auto eth0:2 iface eth0:2 inet static address 192.168.32.47 netmask 255.255.255.0