1. OSI七层模型和TCP/IP模型

    Linux网络配置使用(ifconfig,route,ip)_network


2.IP和TCP报头

 

Linux网络配置使用(ifconfig,route,ip)_network_02

Linux网络配置使用(ifconfig,route,ip)_网络_03

3.预留的私有ip,就是大家都可以使用的

  A类:10.0.0.0/8  1个    其中127用于本地回环

  B类:172.16.0.0/16 -- 172.31.0.0/16  16个

  C类:192.168.0.0/24 -- 192.168.255.0/24  256个


4.ifconfig的使用

ifconfig:
ifconfig - configure a network interface   配置网络接口

SYNOPSIS
   ifconfig [interface]
   ifconfig interface [aftype] options | address ...
This program is obsolete!  For replacement check ip addr and ip link.  
For statistics use ip -s link.       
        默认为显示所有处于激活状态的连接

Linux网络配置使用(ifconfig,route,ip)_网络_04

        ifconfig IFNAME:仅显示指定接口的信息

Linux网络配置使用(ifconfig,route,ip)_network_05        ifconfig IFNAME ADDRESS  设置网络接口的ip地址 
            ip/mask
                长格式:ifconfig IFNAME IP netmask MASK
                短格式:ifconfig IFNAME IP/MASK

Linux网络配置使用(ifconfig,route,ip)_network_06

Linux网络配置使用(ifconfig,route,ip)_网络_07


5.route的使用

    route: 实现路由信息的配置
route - show / manipulate the IP routing table
        route:显示路由信息
            -n: 数字格式的地址
            -n  show numerical addresses instead of trying to determine symbolic
             host names. This is useful if you are trying to determine why the
             route to your nameserver has vanished.

Linux网络配置使用(ifconfig,route,ip)_Linux_08

Gateway 0.0.0.0 说明是本地网络,需要和本地主机在同一个网络内
Destination 0.0.0.0 说明是默认路由
Flags  标志位(标识当前路由信息) 

U  Up表示此路由当前为启动状态

H  Host表示此网关为一主机

G  Gateway表示此网关为一路由器

R  Reinstate Route使用动态路由时,恢复路由信息的标志

D  Dynamically installed by daemon or redirect动态路由

M  Modified from routing daemon or redirect路由已经被修改了

!  Reject route这个路由将不会被接受(用来阻止不安全的网络)

Metric  度量值(用来表示优先级的)
Ref 参考引用
Iface 那通过指定网关需要通过那个接口到达

        add    add a new route. 添加一个路由
            -host:目标为主机
                -host HOST_IP gw NEXT_HOP [dev DEVICE]
            -net:目标是网络
                -net NET_ADDRESS gw NEXT_HOP [dev DEVICE]

                -net 0.0.0.0: 表示目标为任意地址

            route add default gw GW_ADD  添加默认网关
添加10.0.0.0这个网络必须要通过192.168.1.254来转发

Linux网络配置使用(ifconfig,route,ip)_interface_09

添加一条主机路由

Linux网络配置使用(ifconfig,route,ip)_interface_10

添加一条默认路由

Linux网络配置使用(ifconfig,route,ip)_Linux_11

route del
          del    delete a route. 删除一个路由

route  [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]            -host HOST_IP
            -net NET_ADDRESS

删除刚添加的一个网络路由

Linux网络配置使用(ifconfig,route,ip)_Linux_12

删除刚才添加的主机路由

Linux网络配置使用(ifconfig,route,ip)_Linux_13

6.ip的使用

ip(iproute2包生成的)命令:
    ip link : 管理接口
        show [IFNAME] 查看

   ip link set - change device attributes

            up and down
               change the state of the device to UP or DOWN.

        set IFNAME {up(启用)|down(关闭)} 设定
            multicast {on|off}  启用或关闭多播功能

Linux网络配置使用(ifconfig,route,ip)_network_14

Linux网络配置使用(ifconfig,route,ip)_网络_15

  添加或删除一个地址
      ip addr {add|del} ADDRESS dev DEVICE  [label IFALIAS] [broadcast BCAST_ADDRESS]

[ scope SCOPE-ID ] 地址的作用范围
          SCOPE-ID := [ host | link | global | NUMBER ]

显示ip地址,这里显示的信息比ip link show 详细

Linux网络配置使用(ifconfig,route,ip)_网络配置_16

不指定别名给eth0添加ip地址

Linux网络配置使用(ifconfig,route,ip)_Linux_17


指定别名给eth0添加ip地址

Linux网络配置使用(ifconfig,route,ip)_interface_18

删除ip地址

Linux网络配置使用(ifconfig,route,ip)_network_19

Linux网络配置使用(ifconfig,route,ip)_interface_20

ip route: 管理路由
        ip route list  显示路由列表

        ip route flush  清空路由表

        ip route add DESTINATION [via NEXT_HOP] [src SOURCE_ADDRESS] [dev DEVICE]
        ip route del DESTINATION

Linux网络配置使用(ifconfig,route,ip)_interface_21

添加默认路由

Linux网络配置使用(ifconfig,route,ip)_Linux_22

删除路由

Linux网络配置使用(ifconfig,route,ip)_Linux_23