Linux靜態路由配製命令詳解

http://www.num123.com/post/68


一、先熟悉一下配置IP地址的命令ifconfig

      ifconfig eth0 up       //啓用網卡

      ifconfig eth0 down     //關閉網卡

      ifconfig eth0 192.168.1.1 netmask 255.255.255.0 up  

      //給網卡eth0配置IP地址和子網掩碼並啓用

二、查看內核路由表

1、用route 命令查看系統路由表信息

    route命令格式: 
    route [-cfvnee] [選項] 
    主要選項如下。 
    -n:不顯示域名。 
    -e:顯示其他信息。 
    -v:顯示詳細信息。 
    -F:顯示FIB信息。 
    -C:顯示FIB緩存信息。 
    add:增加路由。 
    del: 刪除路由。 
    -net:路由到達的是一個網絡,而不是一臺主機。 
    -host:路由到達的是一臺主機。 
    -netmask Nm:指定路由的子網掩碼。 
    gw:指定路由的網關。


2、也可能用netstat -rn查看路由表信息


3、路由表輸出選項說明


三、用route命令添加刪除路由

1、添加到主機的路由

     route add -host 192.168.100.50  dev eth0

     或者

     route add -host 192.168.100.50 gw 192.168.112.1

2、添加到網絡的路由

    route add -net 192.168.100.0 netmask 255.255.255.0 dev eth0

    或者

    route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.112.1

    或者

    route add -net 192.168.100.0/24 eth0

    添加默認網關路由  route add default gw 192.168.112.1

3、刪除路由

     route del -host 192.168.100.50 dev eth0

     route del -host  192.168.100.50 gw 192.168.112.1

     route del -net 192.168.100.0 netmask 255.255.255.0 dev eth0

     route del -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.112.1

     刪除默認網關路由 route del default gw 1921.68.112.1

 

注:配置完路由條目後一定要打開內核的數據包轉發功能

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

發佈了28 篇原創文章 · 獲贊 26 · 訪問量 32萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章