IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> Linux基础之网络配置 -> 正文阅读

[系统运维]Linux基础之网络配置

一、查看网络配置

1.查看网络接口状态

[root@node1 ~]# ifconfig ens224
ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.11  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::1344:2c57:66a9:99a6  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4e:fd:bc  txqueuelen 1000  (Ethernet)
        RX packets 139628  bytes 15557286 (14.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 156135  bytes 20632958 (19.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


2.查看网关路由信息

[root@node1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.200.2   0.0.0.0         UG    100    0        0 ens160
0.0.0.0         192.168.8.1     0.0.0.0         UG    101    0        0 ens224
0.0.0.0         192.168.9.1     0.0.0.0         UG    102    0        0 ens256
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.8.0     0.0.0.0         255.255.255.0   U     101    0        0 ens224
192.168.9.0     0.0.0.0         255.255.255.0   U     102    0        0 ens256
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.200.0   0.0.0.0         255.255.255.0   U     100    0        0 ens160

3.查看dns信息

[root@node1 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.200.150
nameserver 192.168.8.1
nameserver 192.168.9.1
[root@node1 ~]# 

二、ifconfig网络管理工具使用

1.查看已激活网卡信息

[root@node1 ~]# ifconfig 
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:3bff:fe27:6e  prefixlen 64  scopeid 0x20<link>
        ether 02:42:3b:27:00:6e  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 28  bytes 3955 (3.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.200.135  netmask 255.255.255.0  broadcast 192.168.200.255
        inet6 fe80::79d4:c66c:4dfd:8050  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4e:fd:b2  txqueuelen 1000  (Ethernet)
        RX packets 63413  bytes 4855353 (4.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 51247  bytes 3972067 (3.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.11  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::1344:2c57:66a9:99a6  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4e:fd:bc  txqueuelen 1000  (Ethernet)
        RX packets 141667  bytes 15779234 (15.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 158353  bytes 20924018 (19.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens256: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.9.11  netmask 255.255.255.0  broadcast 192.168.9.255
        inet6 fe80::98f4:d12d:141:ed83  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4e:fd:c6  txqueuelen 1000  (Ethernet)
        RX packets 20102  bytes 4249700 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14190  bytes 1560464 (1.4 MiB)
        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 1000  (Local Loopback)
        RX packets 3834  bytes 280418 (273.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3834  bytes 280418 (273.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethe519a37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::98e4:e9ff:feda:7799  prefixlen 64  scopeid 0x20<link>
        ether 9a:e4:e9:da:77:99  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 50  bytes 6321 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethef87674: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::3c42:a8ff:fef3:e316  prefixlen 64  scopeid 0x20<link>
        ether 3e:42:a8:f3:e3:16  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 50  bytes 6321 (6.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:00:3f:0a  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.查看所有网卡(包括未激活)网卡信息

[root@node1 ~]# ifconfig -a

3.设置网卡激活及禁用

[root@node1 ~]# ifconfig ens224 up
[root@node1 ~]# ifconfig ens224 down

4.配置网卡IP地址

[root@node1 ~]# ifconfig ens224 172.25.25.21/24

三、nmcli网络管理工具使用

1.新加网卡配置文件

[root@node1 ~]# nmcli connection add ifname ens224 type ethernet con-name ens224-con224 ipv4.addresses  192.168.8.11/24 ipv4.gateway 192.168.8.1 ipv4.dns 192.168.8.1 ipv4.method manual
[root@node1 ~]# nmcli connection reload 
[root@node1 ~]# nmcli connection up ens224-con224 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@node1 ~]# 

2.修改网卡配置文件

[root@node1 ~]# nmcli connection modify ens224-con224 ipv4.addresses 192.168.8.11/24 ipv4.gateway 192.168.8.1 ipv4.dns 192.168.8.1 ipv4.method manual 
[root@node1 ~]# nmcli connection reload 
[root@node1 ~]# nmcli connection up ens224-con224 

3.新加网卡IP地址

nmcli connection modify ens224-con224 +ipv4.addresses 192.168.8.111/24
[root@node1 ~]# nmcli con up ens224-con224 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
[root@node1 network-scripts]# ip addr show ens224
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4e:fd:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.11/24 brd 192.168.8.255 scope global noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet 192.168.8.111/24 brd 192.168.8.255 scope global secondary noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet6 fe80::1344:2c57:66a9:99a6/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@node1 network-scripts]#

4.查看网卡配置文件状态

[root@node1 network-scripts]# nmcli connection show 
NAME           UUID                                  TYPE      DEVICE  
docker0        ff8dae9c-631f-4e9d-961b-d5e09c85dbaa  bridge    docker0 
ens160         142fe7fb-a214-497f-a638-accac6a8407d  ethernet  ens160  
ens224-con224  1244a360-7311-472f-b6bd-25186c342c67  ethernet  ens224  
ens224-con256  a87770e8-3b7a-4cb4-9fbe-45bc08388cb8  ethernet  ens256  
virbr0         d7a40851-e7dc-477d-b479-e26eb4895d2b  bridge    virbr0  
[root@node1 network-scripts]# 

5.查看网卡设备状态

[root@node1 network-scripts]# nmcli device  status 
DEVICE       TYPE      STATE      CONNECTION    
ens160       ethernet  connected  ens160        
ens224       ethernet  connected  ens224-con224 
docker0      bridge    connected  docker0       
ens256       ethernet  connected  ens224-con256 
virbr0       bridge    connected  virbr0        
vethe519a37  ethernet  unmanaged  --            
vethef87674  ethernet  unmanaged  --            
lo           loopback  unmanaged  --            
virbr0-nic   tun       unmanaged  --            
[root@node1 network-scripts]# 

6.连接或断开网卡设备

[root@node1 network-scripts]# nmcli device disconnect/connect ens224

四、IP网络管理工具使用

1.查看网卡设备信息

[root@node1 network-scripts]# ip link  show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:4e:fd:b2 brd ff:ff:ff:ff:ff:ff
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:4e:fd:bc brd ff:ff:ff:ff:ff:ff
4: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:4e:fd:c6 brd ff:ff:ff:ff:ff:ff
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:3b:27:00:6e brd ff:ff:ff:ff:ff:ff
7: vethef87674@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default 
    link/ether 3e:42:a8:f3:e3:16 brd ff:ff:ff:ff:ff:ff link-netnsid 1
9: vethe519a37@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default 
    link/ether 9a:e4:e9:da:77:99 brd ff:ff:ff:ff:ff:ff link-netnsid 0
10: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:00:3f:0a brd ff:ff:ff:ff:ff:ff
11: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 52:54:00:00:3f:0a brd ff:ff:ff:ff:ff:ff

2.激活或禁用网卡

[root@node1 network-scripts]# ip link set ens224 up/down

3.查看网络地址

[root@node1 network-scripts]# 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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4e:fd:b2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.200.135/24 brd 192.168.200.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::79d4:c66c:4dfd:8050/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4e:fd:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.11/24 brd 192.168.8.255 scope global noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet 192.168.8.111/24 brd 192.168.8.255 scope global secondary noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet6 fe80::1344:2c57:66a9:99a6/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
4: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4e:fd:c6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.9.11/24 brd 192.168.9.255 scope global noprefixroute ens256
       valid_lft forever preferred_lft forever
    inet6 fe80::98f4:d12d:141:ed83/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:3b:27:00:6e brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:3bff:fe27:6e/64 scope link 
       valid_lft forever preferred_lft forever
7: vethef87674@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default 
    link/ether 3e:42:a8:f3:e3:16 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::3c42:a8ff:fef3:e316/64 scope link 
       valid_lft forever preferred_lft forever
9: vethe519a37@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default 
    link/ether 9a:e4:e9:da:77:99 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::98e4:e9ff:feda:7799/64 scope link 
       valid_lft forever preferred_lft forever
10: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:00:3f:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
11: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:00:3f:0a brd ff:ff:ff:ff:ff:ff
[root@node1 network-scripts]# 

4.网卡新增IP和删除IP地址

[root@node1 network-scripts]# 
[root@node1 network-scripts]# ip addr add 192.168.8.222/24 dev ens224
[root@node1 network-scripts]# ip addr del 192.168.8.222/24 dev ens224

5.管理路由表

①查看路由表

[root@node1 ~]# ip route show
default via 192.168.200.2 dev ens160 proto static metric 100 
default via 192.168.9.1 dev ens256 proto static metric 102 
default via 192.168.8.1 dev ens224 proto static metric 103 
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 
192.168.8.0/24 dev ens224 proto kernel scope link src 192.168.8.11 metric 103 
192.168.8.0/24 dev ens224 proto kernel scope link src 192.168.8.111 metric 103 
192.168.9.0/24 dev ens256 proto kernel scope link src 192.168.9.11 metric 102 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 
192.168.200.0/24 dev ens160 proto kernel scope link src 192.168.200.135 metric 100

②.新增静态路由

[root@node1 ~]# ip route add 192.168.120.0/24 via 192.168.8.1 
[root@node1 ~]# ip route 
default via 192.168.200.2 dev ens160 proto static metric 100 
default via 192.168.9.1 dev ens256 proto static metric 102 
default via 192.168.8.1 dev ens224 proto static metric 103 
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 
192.168.8.0/24 dev ens224 proto kernel scope link src 192.168.8.11 metric 103 
192.168.8.0/24 dev ens224 proto kernel scope link src 192.168.8.111 metric 103 
192.168.9.0/24 dev ens256 proto kernel scope link src 192.168.9.11 metric 102 
192.168.120.0/24 via 192.168.8.1 dev ens224 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 
192.168.200.0/24 dev ens160 proto kernel scope link src 192.168.200.135 metric 100 
[root@node1 ~]# 

③.删除路由

[root@node1 ~]# ip route del 192.168.120.0/24 via 192.168.8.1

五、网络其他命令

1.查看网卡配置文件

[root@node1 ~]# cd /etc/sysconfig/network-scripts/
[root@node1 network-scripts]# ls
ifcfg-ens160  ifcfg-ens224-con224  ifcfg-ens224-con256
[root@node1 network-scripts]# cat ifcfg-ens224-con224 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.8.11
PREFIX=24
GATEWAY=192.168.8.1
DNS1=192.168.8.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens224-con224
UUID=1244a360-7311-472f-b6bd-25186c342c67
DEVICE=ens224
ONBOOT=yes
IPADDR1=192.168.8.111
PREFIX1=24
[root@node1 network-scripts]# 

2.查看及设置主机名

[root@node1 network-scripts]# hostname
node1

[root@node1 network-scripts]# hostnamectl set-hostname test
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-08-24 15:57:18  更:2021-08-24 16:00:55 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 12:09:54-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码