Linux網路設定之vlan與路由

來源:互聯網
上載者:User

===================================== vlan設定 ===============================================

轉自:http://hi.baidu.com/autoelectron/item/223c0baf327477aa28ce9d3d

載入802.1q模組

[root@test0001~]#yum install vconfig
[root@test0001~]#modprobe 8021q
[root@test0001~]#lsmod |grep -i 8021q


在eth0物理網卡上配置兩個vlan

[root@test0001~]#vconfig
add eth0 100
Added VLAN with VID == 100 to IF -:eth0:-
[root@test0001~]#vconfig add eth0 200
Added VLAN with VID == 200 to IF -:eth0:-


設定VLAN的REORDER_HDR參數,預設就行了。

[root@test0001~]#vconfig set_flag eth0.100 1 1
Set flag on device -:eth0.100:- Should be visible in/proc/net/vlan/eth0.100
[root@test0001~]#vconfig set_flag eth0.200 1 1
Set flag on device -:eth0.200:- Should be visible in/proc/net/vlan/eth0.200

配置兩個vlan介面的IP地址,並啟動

[root@test0001~]#ifconfig
eth0 0.0.0.0
[root@test0001~]#ifconfig eth0.100 172.16.1.8 netmask 255.255.255.0up
[root@test0001~]#ifconfig eth0.200 172.16.2.8 netmask 255.255.255.0up


刪除vlan

[root@test0001~]#vconfig
rem eth0.100
Removed VLAN -:eth0.100:-
[root@test0001~]#vconfig rem eth0.200
Removed VLAN -:eth0.200:-

===================================== 路由設定 ===============================================

轉自:http://blog.csdn.net/moreorless/article/details/5397427

linux下靜態路由修改命令

方法一:
添加路由
route add -net 192.168.0.0/24 gw 192.168.0.1
route add -host 192.168.1.1 dev 192.168.0.1
刪除路由
route del -net 192.168.0.0/24 gw 192.168.0.1

add 增加路由
del 刪除路由
-net 設定到某個網段的路由
-host 設定到某台主機的路由
gw 出口網關 IP地址
dev 出口網關 物理裝置名稱

增 加預設路由

route add default gw 192.168.0.1
預設路由一條就夠了

route -n 查看路由表

方法二:
添加路由
ip route add 192.168.0.0/24 via 192.168.0.1
ip route add 192.168.1.1 dev 192.168.0.1
刪除路由
ip route del 192.168.0.0/24 via 192.168.0.1

add 增加路由
del 刪除路由
via 網關出口 IP地址
dev 網關出口 物理裝置名稱

增加預設路由
ip route add default via 192.168.0.1 dev eth0
via 192.168.0.1 是我的預設路由器

查看路由資訊
ip route

儲存路由設定,使其在網路重啟後任然有效 
在/etc/sysconfig/network-script/目錄下建立名為route- eth0的檔案 
vi /etc/sysconfig/network-script/route-eth0 
在此檔案添加如下格式的內容 

192.168.1.0/24 via 192.168.0.1 

重啟網路驗證

 

 

/etc/rc.d/init.d/network中有這麼幾行:

# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
fi 

也就是說,將靜態路由加到/etc/sysconfig/static-routes 檔案中就行了。

 

如加入:
route add -net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1

則static-routes的格式為
any net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.