# 网络配置命令详解

* ip

```shell
ip(选项)(参数)
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
```

```shell
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
        -h[uman-readable] | -iec |
        -f[amily] { inet | inet6 | ipx | dnet | bridge | link } |
        -4 | -6 | -I | -D | -B | -0 |
        -l[oops] { maximum-addr-flush-attempts } |
        -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
        -rc[vbuf] [size] | -n[etns] name | -a[ll] }

网络对象：指定要管理的网络对象；
具体操作：对指定的网络对象完成具体操作；
help：显示网络对象支持的操作命令的帮助信息。
```

```shell
OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
       tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
       netns | l2tp | macsec | tcp_metrics | token }

-V：显示指令版本信息；
-s：输出更详细的信息；
-f：强制使用指定的协议族；
-4：指定使用的网络层协议是IPv4协议；
-6：指定使用的网络层协议是IPv6协议；
-0：输出信息每条记录输出一行，即使内容较多也不换行显示；
-r：显示主机时，不使用IP地址，而使用主机的域名。
```

```shell
ip link show                     # 显示网络接口信息
ip link set eth0 up             # 开启网卡
ip link set eth0 down            # 关闭网卡
ip link set eth0 promisc on      # 开启网卡的混合模式
ip link set eth0 promisc offi    # 关闭网卡的混个模式
ip link set eth0 txqueuelen 1200 # 设置网卡队列长度
ip link set eth0 mtu 1400           # 设置网卡最大传输单元
ip addr show     				  # 显示网卡IP信息
ip addr add 192.168.0.1/24 dev eth0 # 设置eth0网卡IP地址192.168.0.1
ip addr del 192.168.0.1/24 dev eth0 # 删除eth0网卡IP地址

ip route show 							# 显示系统路由
ip route add default via 192.168.1.254   # 设置系统默认路由
ip route list                 			# 查看路由信息
ip route add 192.168.4.0/24  via  192.168.0.254 dev eth0 # 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口
ip route add default via  192.168.0.254  dev eth0        # 设置默认网关为192.168.0.254
ip route del 192.168.4.0/24   # 删除192.168.4.0网段的网关
ip route del default          # 删除默认路由
ip route delete 192.168.1.0/24 dev eth0 # 删除路由
```

* route

  ```shell
  添加删除默认路由：
  1.route del default gw 82.17.68.254
  2.route add default gw 82.17.68.54
  ```

```shell
route add –net 180.200.0.0 netmask 255.255.0.0 gw 10.200.6.201 dev eth0 metric 1

route add：表示增加路由，若要删除路由，则为route del
-host/-net：表示路由目标是主机还是网段
netmask：表示路由目标为网段时才会使用到，表示路由目标网段的子网掩码
gw：后面跟下一跳网关；
dev：后面跟具体设备名，表示路由是从该设备出去
metric：度量值（范围是 1 ~ 9999），它用来在路由表里的多个路由中选择与转发包中的目标地址最为匹配的路由。所选的路由具有最少的跃点数。跃点数能够反映跃点的数量、路径的速度、路径可靠性、路径吞吐量以及管理属性

```

* nmcli

  ```shell
  注:**
  **1.centos8采用nmcli统一管理网络 ， 手动更改配置文件只能临时生效**
  **2.执行完nmcli命令后，需采用 例如nmcli connection up ens18 （针对某网卡生效）或者 nmcli networking off ; nmcli networking on 重启网络服务**

  查看网络信息
  nmcli

  添加ipv4 ip
  nmcli connection modify ens18 +ipv4.addresses 10.61.74.56/23
  删除ipv4 ip
  nmcli connection modify ens18 -ipv4.addresses 10.61.74.56/23

  开启网卡
  nmcli connection up ens18
  关闭网卡
  nmcli connection down ens18

  添加ipv6 ip
  nmcli connection modify ens18 +ipv6.addresses fe81::/64
  删除ipv6 ip
  nmcli connection modify ens18 -ipv6.addresses fe81::/64

  添加ipv4路由
  nmcli connection modify ens18 +ipv4.routes "10.61.74.57/23 10.61.74.1 "
  nmcli connection up ens18


  删除ipv4路由
  nmcli connection modify ens18 -ipv4.routes "10.61.74.57/23 10.61.74.1 "

  添加ipv6路由
  nmcli connection modify ens18 +ipv6.routes fe81::/64
  删除ipv6路由
  nmcli connection modify ens18 -ipv6.routes fe81::/64

  添加ipv4 dns
  nmcli connection modify ens18 +ipv4.dns  200.200.10.199

  删除ipv4 dns
  nmcli connection modify ens18 -ipv4.dns  200.200.10.199

  添加ipv6 dns
  nmcli connection modify ens18 +ipv6.dns 2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b

  删除ipv6 dns
  nmcli connection modify ens18 -ipv6.dns 2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b

  配置

  nmcli connection add type ethernet ifname ens19 con-name ens19 ipv4.addresses 192.168.44.55/16 ipv4.gateway 192.168.44.1 ipv4.method manual

  查看路由配置

  route -n

  修改路由对应的度量值

  nmcli connection modify ens19 ipv4.routes '0.0.0.0/0 10.61.74.25 155'
  ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qiangrens-organization.gitbook.io/qkd90/fu-wu-qi-yun-wei-he-ce-shi/linux-fu-wu-qi/wang-luo-pei-zhi-ming-ling-xiang-jie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
