Linux_ day07_ 05_ Configure common add, delete, modify and query commands in network

configuration network commonly used add, delete, change search command

modify the IP address
  1. modify the configuration file

    /etc/sysconfig/network-scripts/ifcfg-ens33

  2. ifconfig command
    ifconfig ens33:0 192.168.235.127/24
    

  3. IP command
    ip addr add 192.168.235.127/24 dev ens33 label ens33:1
    

  4. nmcli command
    nmcli connection modify ens33 ipv4.address 192.168.80.100/24 # 修改ip地址
    nmcli connection modify ens33 ipv4.gateway 192.168.80.2/24 #修改网关
    nmcli connection modify ens33 ipv4.dns1 114.114.114.114 # 修改dns信息
    nmcli connection modify ens33 ipv4.method mannual # 指定网络信息获取方式为手动指定
    
open/disable network card
  1. ifconfig command
    ifconfig ens33 up
    ifconfig ens33 down
    

  2. ifup/ifdown command
    ifup ens33
    ifdown ens33
    

  3. IP command
    ip link set ens33 up
    ip link set ens33 down
    

  4. nmcli command
    nmcli device connect ens33
    nmcli device disconnect ens33
    
add routing
  1. modify the configuration file

    /etc/sysconfig/network-scripts/route-ens33

    The

    • way

      target via gw
      220.181.38.148 via 192.168.80.2

    • each three lines defines a route
      ADDRESS0=TARGET
      NETMASK0=MASK
      GATEWAY0=GW

      Blockquote>

  2. route command
    route add -net 192.168.235.0 netmask 255.255.255.0 gw 192.168.235.2 dev ens33
    

  3. IP command
    ip route add 192.168.80.0/24 via 192.168.80.2 dev ens33 # 添加网络路由
    ip route add 192.168.80.100 via 192.168.80.0 dev ens33 #添加主机路由
    ip route add default via 192.168.80.2 dev ens33 # 添加默认路由
    
modify routing
  1. modify the configuration file

    /etc/sysconfig/network-scripts/route-ens33

    The

    • way

      target via gw
      220.181.38.148 via 192.168.80.2

    • each three lines defines a route
      ADDRESS0=TARGET
      NETMASK0=MASK
      GATEWAY0=GW

      Blockquote>

  2. IP command
    ip route change # 如果路由本身不存在则报错显示不存在
    ip route replace # 如果路由本身不存在则会直接创建该路由信息
    
delete route
  1. delete the configuration file

    /etc/sysconfig/network-scripts/route-ens33

  2. the route command
    route del -net 192.168.235.0 netmask 255.255.255.0 gw 192.168.235.2 dev ens33
    

  3. IP command
    ip route del 192.168.80.0/24 via 192.168.80.2 dev ens33
    
view routing table
  1. the route command
    route -n
    

  2. netstat command
    netstat -r # 显示内核路由表
    netstat -n # 数字格式(不进行反向解析)
    

Read More: