linux雙網絡卡做網橋(二)

2021-09-01 19:25:06 字數 1910 閱讀 4395

位址[url]

若將virtual box的網路連線方式設為nat,則虛擬機器可以直接與外網相連,但不能與宿主機相連。以下將virtual box的網路連線方式設為host inte***ce方式。實現了虛擬機器可以與宿主機相連,同時也可以連線網際網路。

一、主機上已有網絡卡ip為192.168.1.3。在主機上做以下步驟新建一張虛擬網絡卡以供與虛擬機器網路資料交換使用。

(1)、安裝提供tunctl與brctl工具的軟體包

yum install tunctl-1.5-1.fc10 bridge-utils -y

(2)、設定允許**

echo 1 > /proc/sys/net/ipv4/ip_forward

(3)、利用iptables完成ip資料報**功能

iptables -t nat -a postrouting -j masquerade

(4)、設定允許virtual box訪問/dev/net/tun檔案

chmod 0666 /dev/net/tun

(5)、tap裝置tap0當作虛擬網絡卡,其所有者設為mygod使用者,這裡要注意一定要將所有者設成自己的帳戶,否則執行虛擬機會出錯

tunctl -t tap0 -u mygod

(6)、啟用虛擬網絡卡

ifconfig tap0 up

(7)、設定虛擬網絡卡的ip與掩碼

ifconfig tap0 10.0.2.3 netmask 255.255.255.0

二、開啟virtual box,在虛擬機器的網路設定中,將連線方式設為host inte***ce,並且將host inte***ce settings中的inte***ce name填為tap0。

三、進入虛擬機器centos-5.2後,執行以下命令。

(1)、執行system-config-network,對eth0網絡卡作以下設定:

ip:10.0.2.4

netmask:255.255.255.0

gate way:10.0.2.3

(2)、重新啟用eth0網絡卡

ifdown eth0

ifup eth0

四、解決問題:

以上步驟做完之後,在虛擬機器上能夠正確ping到宿主機192.168.1.3,但卻無法連線外網,並且ping閘道器192.168.1.1收到from 10.0.2.3 icmp_seq=1 destination host prohibited的提示。

使用iptables -t filter --list命令後發現filter表中的forward鏈裡有一條

「reject all -- anywhere anywhere reject-with icmp-host-prohibited」。

[color=red]想想應該就是這一條規則作怪,於是執行以下命令:iptables -t filter -f forward。[/color]

ok,現在可以ping通閘道器了,但ping www.163.com還是得到unknown host www.163.com的提示。看來是虛擬機器的dns設定的問題。於是開啟/etc/resolv.conf檔案,填加「nameserver 192.168.3.1」。搞定!

五、宿主機重啟後只要以root帳戶再次執行以下指令碼即可:

#!/bin/bash

tunctl -d tap0

tunctl -t tap0 -u mygod

ifconfig tap0 up

ifconfig tap0 10.0.2.3 netmask 255.255.255.0

iptables -t filter -f forward

iptables -t nat -a postrouting -j snat -s 10.0.2.0/24 --to-source 192.168.3.3

echo 1 > /proc/sys/net/ipv4/ip_forward

linux雙網絡卡繫結

一 原理 linux作業系統下雙網絡卡繫結有七種模式。現在一般的企業都會使用雙網絡卡接入,這樣既能新增網路頻寬,同時又能做相應的冗餘,可以說是好處多多。而一般企業都會使用linux作業系統下自帶的網絡卡繫結模式,當然現在網絡卡產商也會出一些針對windows作業系統網絡卡管理軟體來做網絡卡繫結 wi...

Linux雙網絡卡繫結

用vmware workstation做乙個linux的雙網絡卡繫結,跟著乙個部落格在做然後也找了其他部落格進行對照但是做完一直報錯network無法重啟。下面是我找到的一篇部落格中說 vmware workstation不支援第一種獲取mac位址的方式,那麼可以使用fail over mac 1引...

雙網絡卡做閘道器伺服器

bin bash in eth1 out eth0 etc init.d iptables stop iptables p input accept iptables p output accept iptables p forward drop iptables f iptables a inpu...