《LINUX教程:使用nmcli命令配置網(wǎng)絡(luò)》要點(diǎn):
本文介紹了LINUX教程:使用nmcli命令配置網(wǎng)絡(luò),希望對您有用。如果有疑問,可以聯(lián)系我們。
使用nmcli敕令配置網(wǎng)絡(luò)
NetworkManager是管理和監(jiān)控網(wǎng)絡(luò)設(shè)置的守護(hù)進(jìn)程,設(shè)備既便是網(wǎng)絡(luò)接口,連接是對網(wǎng)絡(luò)接口的配置,一個網(wǎng)絡(luò)接口可以有多個連接配置,但同時(shí)只有一個連接配置生效.
1 設(shè)置裝備擺設(shè)主機(jī)名
CentOS6 之前主機(jī)設(shè)置裝備擺設(shè)文件:/etc/sysconfig/network
CentOS7主機(jī)名設(shè)置裝備擺設(shè)文件:/etc/hostname,默認(rèn)沒有這個文件,通過DNS反向解析獲取主機(jī)名,主機(jī)名默認(rèn)為:localhost.localdomain
顯示主機(jī)名信息
? ? hostname
? ? hostnamectl status
創(chuàng)立并修改文件并生效
hostnamectl set-hostname deskX.example.com
[root@centos73 ~]# hostnamectl set-hostname centos7.3.com [root@centos73 ~]# hostname centos7.3.com [root@centos73 ~]# cat /etc/hostname centos7.3.com
可以看到已經(jīng)修改勝利.
刪除文件.回復(fù)默認(rèn)主機(jī)名localhost.localdomain
2 常用敕令
? ? nmcli connection show 顯示所有銜接
? ? nmcli connection show --active? ? 顯示所有運(yùn)動的連接狀態(tài)
? ? nmcli connection show "ens33"? ? 顯示網(wǎng)絡(luò)銜接配置
? ? nmcli device status? ? ? ? ? ? 顯示裝備狀態(tài)
? ? nmcli device show ens33? ? ? ? 顯示收集接口屬性
? ? nmcli connection add help? ? ? ? 查看贊助
? ? nmcli connection reload? ? ? ? 重新加載設(shè)置裝備擺設(shè)
? ? nmcli connection down test2? ? ? ? 禁用test2的設(shè)置裝備擺設(shè),注意一個網(wǎng)卡可以有多個設(shè)置裝備擺設(shè).
? ? nmcli connection up test2? ? ? ? 啟用test2的設(shè)置裝備擺設(shè)
? ? nmcli device disconnect ens33? ? 禁用ens33網(wǎng)卡,物理網(wǎng)卡
? ? nmcli device disconnect ens33? ? 啟用ens33網(wǎng)卡
圖形對象
? ? nm-connection-editor
字符對象
? ? nmtui
? ? nmtui-connect
? ? nmtui-edit
? ? nmtui-hostname
3 創(chuàng)立新連接配置
(1)創(chuàng)立新連接配置default,IP通過DHCP自動獲取
[root@centos73 ~]# nmcli connection add con-name default type Ethernet ifname eth0 Connection 'default' (d62f98af-86ed-4735-80aa-2d80351765b2) successfully added.
刪除銜接
[root@centos73 ~]# nmcli connection delete default Connection 'default' (d62f98af-86ed-4735-80aa-2d80351765b2) successfully deleted.
(2)創(chuàng)立新的連接配置test2,指定靜態(tài)IP,不自動連接
[root@centos73 ~]# nmcli connection add con-name test2 ipv4.method manual ifname ens33 autoconnect no type Ethernet ipv4.addresses 172.25.100.100/24 gw4 172.25.100.1 Connection 'test2' (98385bf5-8cc3-47e3-a5f2-51e2d736be6d) successfully added.
參數(shù)闡明:
? ? con-name 指定銜接名字,沒有特殊要求,
? ? ipv4.methmod 指定獲取IP地址的方式
? ? ifname 指定網(wǎng)卡設(shè)被名,既便是次配置所生效的網(wǎng)卡
? ? autoconnect 指定是否自動啟動
? ? ipv4.addresses 指定IPv4地址
? ? gw4指定網(wǎng)關(guān)
4查看/etc/sysconfig/network-scripts/目次
會看到多出一個文件ifcfg-test2.闡明添加確實(shí)生效了.
/etc/sysconfig/network-scripts/ifcfg-test2
[root@centos73 ~]# ls /etc/sysconfig/network-scripts/ifcfg-* /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-ens34 /etc/sysconfig/network-scripts/ifcfg-test2
5 啟用test2銜接配置
[root@centos73 ~]# nmcli connection up test2 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7) [root@centos73 ~]# systemctl restart network
看下是否生效
[root@centos73 ~]# nmcli device show ens33 GENERAL.DEVICE: ens33 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:3A:00:82 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: test2 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/7 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 172.25.100.100/24 IP4.GATEWAY: 172.25.100.1 IP6.ADDRESS[1]: fe80::5a5b:2cc3:a448:e2e1/64 IP6.GATEWAY:
好了,基本的IP地址配置勝利
6 改動連接設(shè)置
(1)改動test2為自動啟動
[root@centos73 ~]# nmcli connection modify test2 connection.autoconnect yes
(2)改動DNS為172.25.1.1
[root@centos73 ~]# nmcli connection modify test2 ipv4.dns 172.25.1.1
(3)添加DNS 114.114.114.114
[root@centos73 ~]# nmcli connection modify test2 +ipv4.dns 114.114.114.114
看下是否勝利
[root@centos73 ~]# cat /etc/sysconfig/network-scripts/ifcfg-test2 TYPE=Ethernet [……] NAME=test2 UUID=98385bf5-8cc3-47e3-a5f2-51e2d736be6d DEVICE=ens33 ONBOOT=yes DNS1=172.25.1.1 IPADDR=172.25.100.100 PREFIX=24 GATEWAY=172.25.100.1 DNS2=114.114.114.114
可以看到均已生效
(4)刪除DNS
[root@centos73 ~]# nmcli connection modify test2 -ipv4.dns 114.114.114.114
(5)改動IP地址
[root@centos73 ~]# nmcli connection modify test2 ipv4.addresses 200.100.100.100/24 gw4 200.100.100.1
(6)還可以添加多個IP
[root@centos73 ~]# nmcli connection modify test2 +ipv4.addresses 10.10.10.10/8
7 nmcli 敕令和/etc/sysconfig/network-scripts/ifcfg-*文件的對應(yīng)關(guān)系
ipv4.method manual ?BOOTPROTO=none
ipv4.method auto BOOTPROTO=dhcp
ipv4.addresses "192.0.2.1/24 IPADDR=192.0.2.1 ?
PREFIX=24
gw4?192.0.2.254" ? GATEWAY=192.0.2.254? ? ? ?
ipv4.dns 8.8.8.8 DNS0=8.8.8.8
ipv4.dns-search example.com DOMAIN=example.com
ipv4.ignore-auto-dns true PEERDNS=no
connection.autoconnect yes ONBOOT=yes
connection.id eth0 NAME=eth0
connection.interface-name eth0 DEVICE=eth0
802-3-ethernet.mac-address . . . HWADDR= . . .
本文永遠(yuǎn)更新鏈接地址:
《LINUX教程:使用nmcli命令配置網(wǎng)絡(luò)》是否對您有啟發(fā),歡迎查看更多與《LINUX教程:使用nmcli命令配置網(wǎng)絡(luò)》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/9799.html