网络配置

方法一:动态获取网络

root@localhost Desktop]# nm-connection-editor

首先删除原有的id

点击Create


[root@localhost Desktop]# ifconfig                                                #查看动态id,这个id是向系统发生请求,系统给的id
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 983  bytes 67605 (66.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 378  bytes 44109 (43.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 131  bytes 15036 (14.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 131  bytes 15036 (14.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

方法二:临时修改id

root@localhost Desktop]# ifconfig eth0 172.25.254.110 netmask 255.255.255.0     #临时修改id
[root@localhost Desktop]# ifconfig                                                                                    #查看修改后的id
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.254.110  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 2847  bytes 152012 (148.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 527  bytes 68454 (66.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 135  bytes 15456 (15.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 135  bytes 15456 (15.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@localhost Desktop]# systemctl restart network                                          #重启网络
[root@localhost Desktop]# ifconfig                             #查看id,此时的id是之前的id,所以用ifconfig device id   netmask 255.255.255.0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.254.120 netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 2913  bytes 154868 (151.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 559  bytes 72865 (71.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 139  bytes 15876 (15.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 139  bytes 15876 (15.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

方法三 :没有图形界面可以开启ui界面

ot@localhost Desktop]# nmtui

nmtui           nmtui-connect   nmtui-edit      nmtui-hostname

[root@localhost Desktop]# nmtui-edit


[root@localhost Desktop]# systemctl restart network                               #必须重启网络
[root@localhost Desktop]# ifconfig                                                             #查看id
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.254.125  netmask 255.255.255.255  broadcast 172.25.254.125
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 3840  bytes 197045 (192.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 709  bytes 87238 (85.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 207  bytes 22632 (22.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 207  bytes 22632 (22.1 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

方法四:修改文件来实现修改ip

1.切换到/etc/sysconfig/network-scripts

2.打开ifcfg-xxx  文件,xxx代表链接名

3.编写脚本
cd   /etc/sysconfig/network-scripts/
vim  ifcfg-xxxx
DEVICE=网卡名
NAME=XXXX 链接名称  可加可不加
ONBOOT=yes
BOOTRROTO=dhcp(动态) | none|static(静态)
IPADDR=ip
NETMASK=子网掩码

4.重启网络

systemctl restart network    重启网络

systemctl stop network

如何在文件里加其他ip
cd   /etc/sysconfig/network-scripts/
vim  ifcfg-westos
DEVICE=eth0
NAME=westos 链接名称  可加可不加
ONBOOT=yes
BOOTRROTO= none
IPADDR0=ip
PREFIX0=24
IPADDR1=ip
PREFIX1=24


root@localhost Desktop]# cd  /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# vim  ifcfg-linux

DEVICE=eth0
NAME=linux
ONBOOT=yes
BOOTRROTO=dhcp
IPADDR=171.25.254.150
NETMASK=255.255.255.0
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 171.25.254.150  netmask 255.255.255.0  broadcast 171.25.254.255
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 31  bytes 2826 (2.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56  bytes 9421 (9.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 8  bytes 556 (556.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 556 (556.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

添加多个ip
[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# vim  ifcfg-linux
[root@localhost network-scripts]# systemctl stop network
[root@localhost network-scripts]# systemctl restart network
CE=eth0
NAME=linux
ONBOOT=yes
BOOTRROTO=none
IPADDR0=172.25.254.150
NETMASK0=255.255.255.0
IPADDR1=172.25.254.111
NETMASK1=255.255.255.0

~                                                                               
   root@localhost network-scripts]# ip addr show               #显示ip信息
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:00:3c:0a brd ff:ff:ff:ff:ff:ff
    inet 172.25.254.150/24 brd 172.25.254.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 172.25.254.111/24 brd 172.25.254.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe00:3c0a/64 scope link
       valid_lft forever preferred_lft forever

静态改动态
ot@localhost Desktop]# cd  /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim  ifcfg-linux




CE=eth0
NAME=linux
ONBOOT=yes
BOOTRROTO=dhcp
#IPADDR=171.25.254.150
#NETMASK=255.255.255.0
~                                                                               
~                                                                               
~                                                                               
~            [root@localhost network-scripts]# cd
[root@localhost ~]# systemctl restart network
^C
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 37  bytes 3078 (3.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 61  bytes 9848 (9.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 12  bytes 976 (976.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 976 (976.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

方法五:


nmcli  device   status etho                     显示设备名称
nmcli   device   show  etho                     显示eth0详细信息
nmcli  device   disconnect eth0              ip断开连接
nmcli  device   connect  eth0                   ip连接
nmcli  connection eth0                                  
nmcli  connection  down                           去掉某个链接名,但链接名依然存在
nmcli  connection  up                               添加已有的链接
nmcli  connection delete  westos           删除链接
ifconfig  etho                                             查看ip
nmcli connection  add type ethernet westos(链接名) ifname eth0(设备名) autoconnect yes  动态添加ip,别人给予的,不可选
nmcli connectin  add  type ethernet westos ifname eth0 ip4 id               静态添加ip,可自行选择

dhcp----static       动态改静态
nmcli connection modify ethernet
nmcti connection modify westos  ipv4.addresses 172.25.254.100/24
nmcli  connection modify  westos ipv4.method manual
systemctl restart netword

static----->dhcp    静态改动态
nmcli connection modify westos ipv4.method auto
systemctl restart  network

nmcli connection modify westos ipv4.addresses 172.25.254.200/24            更改静态ip
[root@localhost ~]# nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes
Connection 'westos' (54cb61cc-ae6e-4ab4-9e09-ae2ff7389343) successfully added.
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 52  bytes 3708 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 190  bytes 28772 (28.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 24  bytes 2236 (2.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 24  bytes 2236 (2.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

动态改为静态
[root@localhost ~]# nmcli connection modify westos  ipv4.addresses 172.25.254.150/24
[root@localhost ~]# nmcli connection modify westos  ipv4.method manual
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.254.150  netmask 255.255.255.0  broadcast 172.25.254.255
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 52  bytes 3708 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 225  bytes 34353 (33.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 24  bytes 2236 (2.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 24  bytes 2236 (2.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

静态改动态
[root@localhost ~]# nmcli connection  modify westos ipv4.method auto
[root@localhost ~]# systemctl restart network
^C
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::5054:ff:fe00:3c0a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:3c:0a  txqueuelen 1000  (Ethernet)
        RX packets 52  bytes 3708 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 242  bytes 36471 (35.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 28  bytes 2656 (2.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 28  bytes 2656 (2.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值