實驗:配置靜態路由1

實驗:配置靜態路由1

IP地址規劃如下:實驗:配置靜態路由1

注意,環境準備:
1、MAC地址不要有沖突,如果是復制的虛擬機,對于centos6需刪除網卡定義文件rm -f /etc/udev/rules.d/70-persistent-net.rules
2、清空防火墻iptables -F(查看:iptables -vnL)
3、啟用IP轉發功能:echo 1 > /proc/sys/net/ipv4/ip_forward
4、關閉服務:service NetworkManager stop
主機A:
ifconfig eth0 172.100.0.100/16 up     #配置接口IP
route add default gw 172.100.0.1     #配置默認網關

實驗:配置靜態路由1

主機B:
ifconfig ens33 192.168.0.100/24 up     #配置接口IP
route add default gw 192.168.0.1     #配置默認網關

實驗:配置靜態路由1

路由R1:
#配置接口IP
ifconfig eth0 172.100.0.1/16
ifconfig eth1 10.0.0.1/8
#配置路由表
route add -net 192.168.0.0/24 gw 10.0.0.2

實驗:配置靜態路由1

路由R2:
#配置接口IP
ifconfig eth0 192.168.0.1/24
ifconfig eth1 10.0.0.2/8
#配置路由表
route add -net 172.100.0.0/16 gw 10.0.0.1

實驗:配置靜態路由1

驗證:
mtr traceroute

附錄:

ifconfig命令:

【ifconfig -h】
Usage:
  ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
  [add <address>[/<prefixlen>]]
  [del <address>[/<prefixlen>]]
  [[-]broadcast [<address>]]  [[-]pointopoint [<address>]]
  [netmask <address>]  [dstaddr <address>]  [tunnel <address>]
  [outfill <NN>] [keepalive <NN>]
  [hw <HW> <address>]  [mtu <NN>]
  [[-]trailers]  [[-]arp]  [[-]allmulti]
  [multicast]  [[-]promisc]
  [mem_start <NN>]  [io_addr <NN>]  [irq <NN>]  [media <type>]
  [txqueuelen <NN>]
  [[-]dynamic]
  [up|down] …

  <HW>=Hardware Type.
  List of possible hardware types:
    loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
    slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
    ash (Ash) ether (Ethernet) ax25 (AMPR AX.25)
    netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
    ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
    arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
    sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
    irda (IrLAP) ec (Econet) x25 (generic X.25)
    infiniband (InfiniBand) eui64 (Generic EUI-64)
  <AF>=Address family. Default: inet
  List of possible address families:
    unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
    ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
    ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet)
    ash (Ash) x25 (CCITT X.25)


示例:
    # ifconfig -a
    # ifconfig <interface> [up|down]     啟用|禁用網卡接口,激活|停用,activate|deactivate
    ifdown|ifup <interface>     啟用|禁用網卡接口,其實是刪除了IP,需要有ifcfg-<interface>配置文件
ifconfig <interface> [aftype] options | <address> …
    # ifconfig <interface> <address>[/<prefixlen>] [up|down]
    # ifconfig <interface> <address> [netmask <address>] [up|down]
    注意:立即生效;
    啟用混雜模式:[-]promisc


查看路由命令:
route -n
netstat -nr
ip route


route命令:路由管理

【route –help】
Usage: route [-nNvee] [-FC] [<AF>]           List kernel routing tables
       route [-v] [-FC] {add|del|flush} …  Modify routing table for AF.

       route {-h|–help} [<AF>]              Detailed usage syntax for specified AF.
       route {-V|–version}                  Display version/author and exit.

        -v, –verbose            be verbose
        -n, –numeric            don’t resolve names
        -e, –extend             display other/more information
        -F, –fib                display Forwarding Information Base (default)
        -C, –cache              display routing cache instead of FIB



添加:route add
route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
                              [netmask N] [mss Mss] [window W] [irtt I]
                              [mod] [dyn] [reinstate] [[dev] If]
route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
示例:
    目標:192.168.1.3  網關:172.16.0.1
    # route add -host 192.168.1.3 gw 172.16.0.1 dev eth0
    目標:192.168.0.0 網關:172.16.0.1
    # route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0
    # route add -net 192.168.0.0/24 gw 172.16.0.1 dev eth0
    默認路由,網關:172.16.0.1
    # route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.16.0.1
    # route add default gw 172.16.0.1

刪除:route del
route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]
示例:
    目標:192.168.1.3  網關:172.16.0.1
    # route del -host 192.168.1.3
    目標:192.168.0.0 網關:172.16.0.1
    # route del -net 192.168.0.0 netmask 255.255.255.0

原創文章,作者:Leion,如若轉載,請注明出處:http://www.www58058.com/71834

(0)
LeionLeion
上一篇 2017-03-26 22:08
下一篇 2017-03-26 22:14

相關推薦

  • N21-北京-兔鍋-馬哥教育網絡班21期+第3周課程練習

    1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。    who | cut -d' ' -f1 | uniq   2、取出最后登錄到當前系統的用戶的相關信息。    who | ta…

    系統運維 2016-07-07
  • 編譯安裝Apache

    實驗環境:CentOS 6 安裝包版本:httpd-2.2.29.tar.bz2 一、安裝前準備     (1)、獲取httpd-2.2.29.tar.bz2安裝包     (2)、準備開發工具,安裝相應的包組 yum groupinstall -y&nbsp…

    Linux干貨 2016-08-24
  • lamp的搭建

    方法一編譯安裝amp:   1.系統環境:CentOS 6,7       CentOS6:apr,apr-util的版本為1.3.9,不適合httpd-2.4    CentOS7:apr,apr-util的版本為1.4+2.開發環境需要安裝:    Developm…

    Linux干貨 2016-10-16
  • N26-第十四周

    1、系統的INPUT和OUTPUT默認策略為DROP;[root@centos7 ~]# iptables -P INPUT DROP[root@centos7 ~]# iptables -P OUTPUT DROP1、限制本地主機的web服務器在周一不允許訪問;新請求的速率不能超過100個每秒;web服務器包含了admin字符串的頁面不允許訪問;web服務…

    Linux干貨 2017-06-20
  • 負載調度器:調度算法

    調度算法(ipvs scheduler) 起點公平:平均分配,不管分別干的怎么樣。 結果公平:誰現在還剩下的在處理的少,就分配給誰。      根據其調度時是否考慮各RS當前的負載狀態,可分為靜態方法和動態方法兩種: 靜態方法 靜態方法:僅根據算法本身進行調度; RR      …

    2016-10-28
  • 文件權限

    首先簡單介紹一下文件的屬性: 使用ls -l 長列出-rw-r–r–. 1 root root 1302 Jul 25 10:23 group文件類型|owner權限group權限other權限|硬鏈接數|owner|group|文件大小(bytes)|mtime|文件名 文件類型:     &…

    2017-07-29
欧美性久久久久