Linux基础之网络配置
生活随笔
收集整理的這篇文章主要介紹了
Linux基础之网络配置
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Linux基礎(chǔ)之網(wǎng)絡(luò)配置
- 一、查看網(wǎng)絡(luò)配置
- 1.查看網(wǎng)絡(luò)接口狀態(tài)
- 2.查看網(wǎng)關(guān)路由信息
- 3.查看dns信息
- 二、ifconfig網(wǎng)絡(luò)管理工具使用
- 1.查看已激活網(wǎng)卡信息
- 2.查看所有網(wǎng)卡(包括未激活)網(wǎng)卡信息
- 3.設(shè)置網(wǎng)卡激活及禁用
- 4.配置網(wǎng)卡IP地址
- 三、nmcli網(wǎng)絡(luò)管理工具使用
- 1.新加網(wǎng)卡配置文件
- 2.修改網(wǎng)卡配置文件
- 3.新加網(wǎng)卡IP地址
- 4.查看網(wǎng)卡配置文件狀態(tài)
- 5.查看網(wǎng)卡設(shè)備狀態(tài)
- 6.連接或斷開(kāi)網(wǎng)卡設(shè)備
- 四、IP網(wǎng)絡(luò)管理工具使用
- 1.查看網(wǎng)卡設(shè)備信息
- 2.激活或禁用網(wǎng)卡
- 3.查看網(wǎng)絡(luò)地址
- 4.網(wǎng)卡新增IP和刪除IP地址
- 5.管理路由表
- ①查看路由表
- ②.新增靜態(tài)路由
- ③.刪除路由
- 五、網(wǎng)絡(luò)其他命令
- 1.查看網(wǎng)卡配置文件
- 2.查看及設(shè)置主機(jī)名
一、查看網(wǎng)絡(luò)配置
1.查看網(wǎng)絡(luò)接口狀態(tài)
[root@node1 ~]# ifconfig ens224 ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.8.11 netmask 255.255.255.0 broadcast 192.168.8.255inet6 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 0TX packets 156135 bytes 20632958 (19.6 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 02.查看網(wǎng)關(guān)路由信息
[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 ens1603.查看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網(wǎng)絡(luò)管理工具使用
1.查看已激活網(wǎng)卡信息
[root@node1 ~]# ifconfig docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255inet6 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 0TX packets 28 bytes 3955 (3.8 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.200.135 netmask 255.255.255.0 broadcast 192.168.200.255inet6 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 0TX packets 51247 bytes 3972067 (3.7 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.8.11 netmask 255.255.255.0 broadcast 192.168.8.255inet6 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 0TX packets 158353 bytes 20924018 (19.9 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens256: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.9.11 netmask 255.255.255.0 broadcast 192.168.9.255inet6 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 0TX packets 14190 bytes 1560464 (1.4 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::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 0TX packets 3834 bytes 280418 (273.8 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0vethe519a37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet6 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 0TX packets 50 bytes 6321 (6.1 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0vethef87674: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet6 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 0TX packets 50 bytes 6321 (6.1 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255ether 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 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 02.查看所有網(wǎng)卡(包括未激活)網(wǎng)卡信息
[root@node1 ~]# ifconfig -a3.設(shè)置網(wǎng)卡激活及禁用
[root@node1 ~]# ifconfig ens224 up [root@node1 ~]# ifconfig ens224 down4.配置網(wǎng)卡IP地址
[root@node1 ~]# ifconfig ens224 172.25.25.21/24三、nmcli網(wǎng)絡(luò)管理工具使用
1.新加網(wǎng)卡配置文件
[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.修改網(wǎng)卡配置文件
[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-con2243.新加網(wǎng)卡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 1000link/ether 00:0c:29:4e:fd:bc brd ff:ff:ff:ff:ff:ffinet 192.168.8.11/24 brd 192.168.8.255 scope global noprefixroute ens224valid_lft forever preferred_lft foreverinet 192.168.8.111/24 brd 192.168.8.255 scope global secondary noprefixroute ens224valid_lft forever preferred_lft foreverinet6 fe80::1344:2c57:66a9:99a6/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@node1 network-scripts]#4.查看網(wǎng)卡配置文件狀態(tài)
[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.查看網(wǎng)卡設(shè)備狀態(tài)
[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.連接或斷開(kāi)網(wǎng)卡設(shè)備
[root@node1 network-scripts]# nmcli device disconnect/connect ens224四、IP網(wǎng)絡(luò)管理工具使用
1.查看網(wǎng)卡設(shè)備信息
[root@node1 network-scripts]# ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000link/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 1000link/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 1000link/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 1000link/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 1000link/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 1000link/ether 52:54:00:00:3f:0a brd ff:ff:ff:ff:ff:ff2.激活或禁用網(wǎng)卡
[root@node1 network-scripts]# ip link set ens224 up/down3.查看網(wǎng)絡(luò)地址
[root@node1 network-scripts]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:0c:29:4e:fd:b2 brd ff:ff:ff:ff:ff:ffinet 192.168.200.135/24 brd 192.168.200.255 scope global noprefixroute ens160valid_lft forever preferred_lft foreverinet6 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 1000link/ether 00:0c:29:4e:fd:bc brd ff:ff:ff:ff:ff:ffinet 192.168.8.11/24 brd 192.168.8.255 scope global noprefixroute ens224valid_lft forever preferred_lft foreverinet 192.168.8.111/24 brd 192.168.8.255 scope global secondary noprefixroute ens224valid_lft forever preferred_lft foreverinet6 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 1000link/ether 00:0c:29:4e:fd:c6 brd ff:ff:ff:ff:ff:ffinet 192.168.9.11/24 brd 192.168.9.255 scope global noprefixroute ens256valid_lft forever preferred_lft foreverinet6 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:ffinet 172.17.0.1/16 brd 172.17.255.255 scope global docker0valid_lft forever preferred_lft foreverinet6 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 1inet6 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 0inet6 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 1000link/ether 52:54:00:00:3f:0a brd ff:ff:ff:ff:ff:ffinet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0valid_lft forever preferred_lft forever 11: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000link/ether 52:54:00:00:3f:0a brd ff:ff:ff:ff:ff:ff [root@node1 network-scripts]#4.網(wǎng)卡新增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 ens2245.管理路由表
①查看路由表
[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②.新增靜態(tài)路由
[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五、網(wǎng)絡(luò)其他命令
1.查看網(wǎng)卡配置文件
[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.查看及設(shè)置主機(jī)名
[root@node1 network-scripts]# hostname node1[root@node1 network-scripts]# hostnamectl set-hostname test總結(jié)
以上是生活随笔為你收集整理的Linux基础之网络配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 通过PXE服务器批量安装系统
- 下一篇: Linux系统的磁盘管理