bannerAds
Global
language language

Product

Doc

Support

Menu 

SiliCloud Help Document Center

search

Popular search terms

云服务器 Linux的IP地址设定(ip命令)

Update time 2023-02-28 13:10  Version v2.2
I want feedback 
Collect My collection

IP 命令

主流 Linux 服务器,均支持 ip 命令。
如果您的系统没有默认安装此命令,请通过以下命令安装:
Debian/Ubuntu:

apt install -y iproute2

Redhat/CentOS:

yum install -y iproute2

您可以通过help和官方文档 https://linux.die.net/man/8/ip,系统的学习ip

[root@localhost ~]# ip help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
                   netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |
                   vrf }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -h[uman-readable] | -iec |
                    -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
                    -4 | -6 | -I | -D | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |
                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
                    -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}

下文介绍几种,日常常用的案例。

使用ip 命令设置 IPv4

  1. 显示当前的IPv4设置情况
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether fa:16:3e:53:fd:b7 brd ff:ff:ff:ff:ff:ff
    altname enp0s3
    inet 172.16.0.179/24 metric 100 scope global dynamic ens3
       valid_lft 64677sec preferred_lft 64677sec
    inet6 2400:38e0:1:4002::b5/64 scope global
       valid_lft forever preferred_lft forever
    inet6 2400:38e0:1:4002::3ec/64 scope global
       valid_lft forever preferred_lft forever
    inet6 2400:38e0:1:4002::302/64 scope global
       valid_lft forever preferred_lft forever
    inet6 2400:38e0:1:4002::2cb/64 scope global
       valid_lft forever preferred_lft forever
    inet6 2400:38e0:1:4002::2b4/64 scope global
       valid_lft forever preferred_lft forever
    inet6 2400:38e0:1:4002::29e/64 scope global
       valid_lft forever preferred_lft forever
    inet6 2400:38e0:1:4002::242/64 scope global
       valid_lft forever preferred_lft forever
    inet6 2400:38e0:1:4002::1df/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe53:fdb7/64 scope link
       valid_lft forever preferred_lft forever

2.新增IPv4(请自行替换IP地址和网卡名称)

ip addr add 172.16.0.179/24 dev ens3

3.删除IPv4(请自行替换IP地址和网卡名称)

ip addr del 172.16.0.179/24 dev ens3

4.新增IPv4的默认路由出口(请自行替换 网关IP地址)

ip router add default via 172.16.0.1

使用ip 命令设置 IPv6

1.新增IPv6(请自行替换IP地址和网卡名称)

ip -6 addr add 2400:38e0:1:4002::2cb/64 dev ens3

2.删除IPv6(请自行替换IP地址和网卡名称)

ip -6 addr del 2400:38e0:1:4002::2cb/64 dev ens3

3.新增IPv6的默认路由出口(请自行替换 网关IP地址)

ip -6 router add 2000::/3 via 2400:38e0:1:4002::1

Do you have any suggestions for this document?

Your rating for this document
You can earn up to 7% from Cloud server new purchase -renewal (3%)-upgrade (3%) ,simply click on the affiliate application to become a partner.
AboutWorry-free refund guarantee.

Become a Partner vServer Affiliate marketing

All Rights Reserved ©2024. SICloud® IT (HK) LIMITED | Silicon Cloud™ (Tokyo) LLC (電気通信事業者番号 A-05-20586) |