我是靠谱客的博主 务实老师,这篇文章主要介绍Linux 中的网络Linux中的网络,现在分享给大家,希望可以做个参考。

Linux中的网络

目录

Linux中的网络

 

实验环境

vm中的网络环境

linux中的网络---命令nmcli

修改配置文件

vim /etc/sysconfig/network-scripts/ifcfg-[网卡名]

重要参数:

 

 

 

文件设置完后,需要重启接口和服务

实例

 


实验环境

复制代码
1
2
3
1.需要两个Linux环境:其中一个使用最小安装 2.都添加一块网卡 3.做实验之间,请先最好拍快照

vm中的网络环境

复制代码
1
2
3
4
5
6
7
8
9
1.network //虚拟机和真机之间连了一台路由器 2.bridge(桥接) //虚拟机和真机之间连接了一台交换机 3.HostOnly //虚拟机和真机没有任何关系 查看IP地址 ifconfig 和 ip addr show lspci:是一个用来显示西铜中所有PCl总线设备或者连接到该总线上的所有设备的工具 lspci | grep Ethernet

linux中的网络---命令nmcli

复制代码
1
2
3
4
5
nmcli: 是Linux的内置命令,无需安装 nmcli connection show :列出当前的网卡设备 nmcli connection show'ens33':查看该网卡的详细信息 如果是最小化安装的Linux,nmcli是无法补齐命令的,需要安装如下软件包:yum install bash-completion
复制代码
1
2
3
4
5
6
7
8
9
配置IP地址,手动或者dhcp nmcli connection add con-name "low" type ethernet ifname ens37 nmcli connection add con-name "static" type ethernet ifname ens37 autoconnect no ipv4.addresses 192.168.1.1/24 gw4 192.168.1.254 nmcli connection up "low" nmcli connection up "static" 补充:type后面可以跟ethernet,wifi,bluetooth等 nmcli connection add help --查看所有网卡类型
复制代码
1
2
3
4
5
nmcli connection modify //修改已经设置好的网络 nmcli connection modify static ipv4.dns 8.8.8.8 //设置DNS nmcli connection modify static ipv4.dns 9.9.9.9 //添加一个DNS nmcli connection modify static ipv4。addresses 192.168.1.100/24 gw4 192.168.1.254 //修改IP地址

修改配置文件

 

vim /etc/sysconfig/network-scripts/ifcfg-[网卡名]

重要参数:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
TYPE=Ethernet/bridge //接口类型 BOOTPROTO=dhcp/static/none //激活此接口后,使用什么协议 ONBOOR=yes/on //开机是否激活 DNS1=8.8.8.8 //设置主要DNS DNS2=9.9.9.9 //设置附属DNS IPADDR=192.168.1.100 //设置IP地址 PREFIX=24 //centOS 设置掩码 GATEWAY=192.168.1.254 //设置网关 NAME=static //管理员取的名字 DEVICE=ens37 //设备名字

 

 

文件设置完后,需要重启接口和服务

实例

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[root@localhost ~]# nmcli connection modify 有线连接 1 ipv4.method manual [root@localhost ~]# nmcli connection modify 有线连接 1 ipv4.addresses 192.168.1.2/24 gw4 192.168.1.254 [root@localhost ~]# systemctl restart network [root@localhost ~]# nmcli connection up 有线连接 1 成功激活的连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/27) [root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.153.132 netmask 255.255.255.0 broadcast 192.168.153.255 inet6 fe80::a6ba:5be7:38ad:91d7 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:d7:00:36 txqueuelen 1000 (Ethernet) RX packets 22114 bytes 16585905 (15.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 9512 bytes 776626 (758.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::c105:e733:ff22:a5ad prefixlen 64 scopeid 0x20<link> ether 00:0c:29:d7:00:40 txqueuelen 1000 (Ethernet) RX packets 764 bytes 76570 (74.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 109 bytes 14746 (14.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 修改网卡名字 [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-有线连接_1 [root@localhost ~]# syste[root@localhost ~]# nmcli connection modify ens33 help id low path --temporary uuid [root@localhost ~]# nmcli connection modify ens33 help id low path --temporary uuid mctl restart network (有线连接改成了low)

 

最后

以上就是务实老师最近收集整理的关于Linux 中的网络Linux中的网络的全部内容,更多相关Linux内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(88)

评论列表共有 0 条评论

立即
投稿
返回
顶部