zoukankan      html  css  js  c++  java
  • RHEL7/CentOS7 ip 命令常用用法

    从 RHEL7/CentOS7 开始,net-tools 包从系统中移除,ifconfg/route/ifup/ifdown 等命令均消失,转而以 ip 命令代替上述命令。因此本篇主要列举了如何使用 ip 命令代替上述命令的常用用法

    1. 查看 IP 地址和数据统计

    ifconfig 版本:

    • ifconfig:显示 up 状态的端口信息,包括 ip、mac、统计等。
    • ifconfig -a:显示所有状态的端口信息,包括 ip、mac、统计等。

    ip 版本:

    • ip addr(简写成 ip a):显示所有端口信息,包括 ip、mac、up/down 等。
    • ip -4 a:仅显示带 ipv4 地址的端口信息。
    • ip -s link:显示所有端口统计信息。
    • ip -s link ls eth0:显示 eth0 端口的统计信息。
    • ip -s -s link ls eth0:更详细地显示 error 信息。

    2. 添加/删除端口的 ip 地址

    ifconfig 版本:

    • ifconfig eth0 192.168.120.56 netmask 255.255.255.0:临时添加 eth0 的 ip 地址。

    ip版本:

    • ip addr add 192.168.2.199/24 dev eth0:临时添加 eth0 的 ip 地址。
    • ip addr del 192.168.2.199/24 dev eth0:删除 eth0 的 ip 地址。

    3. UP/DOWN 端口

    ifconfig 版本:

    • ifconfig eth0 up:将端口 eth0 启动。
    • ifconfig eth0 down:将端口 eth0 关闭。

    ifup/ifdown 版本:

    • ifup ifcfg-eth0:将端口 eth0 启动。
    • ifdown ifcfg-eth0:将端口 eth0 关闭。

    ip 版本:

    • ip link set dev eth0 up:将端口 eth0 启动(无需 ifcfg-eth0 文件存在)。
    • ip link set dev eth0 down:将端口 eth0 启动(无需 ifcfg-eth0 文件存在)。

    4. 路由配置

    route 版本:

    • route -n:查看路由信息
    • route add default gw 192.168.1.1 eth0:添加默认网关路由
    • route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0:添加到网络的路由
    • route add -host 10.20.30.148 gw 10.20.30.40:添加到主机的路由

    ip 版本:

    • ip route:查看路由信息
    • ip route add default via 192.168.1.1:添加默认网关路由
    • ip route add 192.168.0.0/24 via 192.168.1.2:添加到网络的路由
    • ip route add 192.168.1.3 via 172.16.0.1 dev eth0:添加到主机的路由

    本文出处 

    https://blog.csdn.net/zzboat0422/java/article/details/93979978

  • 相关阅读:
    asy for
    asy html !
    lib
    git clone 指定 version tag
    git tag
    git clone <url>--depth 、 git clone <url> --recursive
    xelatex CLI
    rsync
    curl options
    [转自]C语言offset_of宏和container_of宏
  • 原文地址:https://www.cnblogs.com/GaZeon/p/12741493.html
Copyright © 2011-2022 走看看