实验:配置静态路由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.178linux.com/71834

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

相关推荐

  • mageedu_20160802

     用户的管理权限设置与更改以及ACL的存在及其实用意义      一.用户的管理权限如何设置与更改以及umask值的含义    由于linux系统是一个多用户使用的系统,对于各个用户指定的文件或目录必须存在一套管理系统,以防止多用户对相同文件的混淆使用。于是催生出了linux系统文件的用户权限设置。…

    Linux干货 2016-08-03
  • 第三周小练习

    1. 列出当前系统上所有已经登陆的用户的用户名,注意,同一个用户登陆多次,则显示一次即可 who -u|grep -o "^[[:alnum:]]*\>"|uniq 2. 取出最后登陆到当前系统的用户信息 who|tail -n1 3. 取出当前系统上被用户当作其默认shell的最多的那个sh…

    Linux干货 2016-11-21
  • lamp简介

    lamp 构建一个有着动态服务器端技术的网站 LAMP基础 1)开源领域LAMP组成: L:Linux;A:apache (httpd);M:mysql, mariadb;P:php, perl, python httpd:接收用户的web请求;静态资源则直接响应;动态资源为php脚本交由php来运行; php:运行p…

    Linux干货 2016-11-07
  • 实战自制Linux操作系统

    实战自制Linux操作系统 自制linux系统 步骤概述: 1、新建一个硬盘2、在该新硬盘上新建两个分区,一个当boot分区,一个当/分区3、格式化并且挂载两个分区4、安装grub至目标磁盘5、为grub提供配置文件6、复制内核文件和initrd文件7、创建目标主机根文件系统8、移植bash命令和其库文件到根文件系统9、装载模块,实现网络功能10、启动测试 …

    Linux干货 2016-09-19
  • RHCE基础实验

    实验:配额实现 1. 启用配额功能 vim /etc/fstab defaults usrquota,grpquota mount -o remount /home 2. 创建配额数据库 quotacheck -cug /home 3. 启用数据库 quotaon /home quotaon -p /home 查看 4. edquota wang setqu…

    Linux干货 2017-05-02
  • 互联网安全之sudo使用指南

    一、前言 sudo是什么? sudo是系统管理指令;由于root用户权限过大,在实际生产过程中很少使用root用户直接登录系统,而是使用普通用户登录系统;但是如果普通用户要对系统进行日常维护操作时需要su到root用户,为了提高安全性,可以使用sudo授权某一用户在某一主机以某一用户身份运行某些命令;从而减少root用户密码知晓人,提高系统安全性。 &nbs…

    2015-06-23