2017-02-27 22 views
0

我在裝有4塊網卡的計算機上安裝了Ubuntu 16.04服務器。我有連接到同一個交換機的接口eth0eth1。接口eth0用於遠程SSH連接來管理服務器。我想用eth1橋接br0。這座橋我想用於LXC容器。在DHCP環境中這種設置不會導致任何問題。挑戰在於該服務器安裝的網絡完全是靜態的。我收到了具有相同子網掩碼和網關的此服務器的IP範圍。需要配置第二塊網卡才能連接LXC

設置eth0是沒有問題的:

auto eth0 
iface eth0 inet static 
    address 195.x.x.2 
    network 195.x.x.0 
    netmask 255.255.255.0 
    gateway 195.x.x.1 
    broadcast 195.x.x.255 
    dns-nameservers 150.x.x.105 150.x.x.106 

這個問題是與第二接口eth1,因爲它具有相同的網關eth0 Ubuntu的警告,只有一個默認網關設置(這是合乎邏輯) 。爲此我已成立eth1如下:

auto eth1 
iface eth1 net static 
    address 195.x.x.3 
    network 195.x.x.0 
    netmask 255.255.255.0 
    broadcast 195.x.x.255 

問題與此設置是,我可以在外部的ping eth0的IP處,但195.x.x.2eth1不能ping或者通過SSH訪問。我設法使它適用於很多路由技巧,但許多文章都寫道,如果你有靜態網橋和容器的話,這種方式會變得更深。

我的問題是:有沒有人對我的問題有直接的方法?我應該如何配置eth0eth1以將靜態IP號碼的容器橋接到eth1

回答

0

好吧,我按照以下方式解決了這個問題,仍然按照問題描述的方式繼續使用網關路由解決方案。也許有同樣問題的人也可以使用這種方法,或者如果有人知道更好的解決方案可以隨意發表評論。

在主機:

我啓用ARP過濾:

sysctl -w net.ip4.conf.all.arp_filter=1 
echo "net.ipv4.conf.all.arp_filter = 1" >> /etc/sysctl.conf 

配置/etc/network/interfaces

auto lo 
iface lo net loopback 

# The primary network interface 
auto etc0 
iface eth0 inet static 
    address 195.x.x.2 
    network 195.x.x.0 
    netmask 255.255.255.0 
    gateway 195.x.x.1 
    broadcast 195.x.x.255 
    up ip route add 195.x.x.0/24 dev eth0 src 195.x.x.2 table eth0table 
    up ip route add default via 195.x.x.1 dev eth0 table eth0table 
    up ip rule add from 195.x.x.2 table eth0table 
    up ip route add 195.x.x.0/24 dev eth0 src 195.0.0.2 
    dns-nameservers 150.x.x.105 150.x.x.106 

# The secondary network interface 
auto eth1 
iface eth1 net manual 

# LXC bridge interface 
auto br0 
iface br0 inet static 
    address 195.x.x.3 
    network 195.x.x.0 
    netmask 255.255.255.0 
    bridge_ifaces eth1 
    bridge_ports eth1 
    bridge_stp  off 
    bridge_fd  0 
    bridge_maxwait 0 
    up ip route add 195.x.x.0/24 dev br0 src 195.x.x.3 table br0table 
    up ip route add default via 195.x.x.1 dev br0 table br0table 
    up ip rule add from 195.x.x.3 table br0table 
    up ip route add 195.x.x.0/24 dev br0 src 195.0.0.3 

添加以下行/etc/iproute2/rt_tables

... 
10 et0table 
20 br0table 

在容器配置文件(/var/lib/lxc/[container name]/config):

... 
lxc.network.type = vets 
lxc.network.link = br0 
lxc.network.flags = up 
lxc.network.hwadr = [auto create when bringing up container] 
lxc.network.ipv4 = 195.x.x.4/24 
lxc.network.ipv4.gateway = 195.x.x.1 
lxc.network.veth.pair = [readable server name] (when using ifconfig) 
lxc.start.auto = 0 (1 if you want the server to autostart) 
lxc.start.delay = 0 (fill in seconds you want the container to wait before start) 

我通過使在容器上的apache2測試了它和來自網絡外部訪問的網頁。希望它能幫助任何遇到我所遇到的同樣挑戰的人。注意:如果您選擇讓容器的配置文件分配IP,請在容器本身的界面文件中將其禁用,否則請不要忘記。

auto lo 
iface lo inet loopback 

auto eth0 
iface eth0 net manual 
相關問題