实验:配置静态路由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

相关推荐

  • php-fpm

    1.安装 mariadb 服务 修改配置文件 2.musql 安全加强 3.安装 php-fpm php-mysql php-mbstring php-mcrypt 服务 修改配置文件 4.安装httpd服务 加虚拟主机配置文件 5.测试php网页 6.安装myadmin包及测试

    2017-06-04
  • N26_第一周作业

    一、描述计算机的组成及其功能。 计算机系统:是由硬件(Hardware)系统和软件(Software)系统两大部分构成。 1、硬件系统: 1)控制器(Control):是整个计算机的中枢神经,其功能是对程序规定的控制信息进行解释,根据其要求进行控制,调度程序、数据、地址,协调计算机各部分工作及内存与外设的访问等。2)运算器(Datapath):运算器的功能是…

    2017-02-20
  • shell脚本小练习..

    刚刚接触vim和shell脚本,用几个小脚本练练手。 1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 2、编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到/root/etcYYYY-mm-dd中。 3、编写脚本…

    2017-04-13
  • linux软件包管理(开始上正菜了)

    linux程序包管理:     API:数据接口     ABI:应用程序二进制接口        库级别的虚拟化:             linux:wine    …

    Linux干货 2017-03-07
  • zabbix表分区(适用于zabbix2.0.x,zabbix2.2.x和zabbix2.4.x)

    本文主要介绍了zabbix进行数据库表分区的方法:         在系统监控中,zabbix已经代替了nagios+cacti,zabbix以其良好的图形展示和高度自定义赢得了很多运维人员的喜爱。但是由于在工作中,zabbix跑的时间过长(我们公司跑了将近3年),web页面经常卡顿,监控…

    Linux干货 2015-10-27
  • 马哥教育网络第21期-第十二周课程练习

    1、请描述一次完整的http请求处理过程; (1) 建立或处理连接:接收请求或拒绝请求 (2) 接收请求:接收来自于网络的请求报文中对某资源的一次请求的过程;并发访问响应模型(Web I/O): //服务器接受客户端的请求 单进程I/O结构:启动一个进程处理用户请求,而且一次只处理一个;多个请求被串行响应; //一个进程只有一个…

    Linux干货 2016-12-26