環(huán)境準(zhǔn)備:新安裝的CentOS7.x,,最小化安裝,沒有進(jìn)行網(wǎng)絡(luò)配置。
1,、查看當(dāng)前網(wǎng)卡信息
[root@localhost ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 5d58d8cc-8caf-458b-a672-ed0cdf58292e 802-3-ethernet ---
CentOS7中對網(wǎng)上的命名規(guī)則有所變更,,具體規(guī)則如下:
eno1 :代表由主板 BIOS 內(nèi)建的網(wǎng)卡
ens1 :代表由主板 BIOS 內(nèi)建的 PCI-E 界面的網(wǎng)卡
enp2s0 :代表 PCI-E 界面的獨(dú)立網(wǎng)卡,,可能有多個(gè)網(wǎng)卡接口,,因此會(huì)有 s0, s1... 的編號(hào)
eth0 :如果上述的名稱都不適用,就回到原本的預(yù)設(shè)網(wǎng)卡編號(hào)
由于現(xiàn)在網(wǎng)卡沒有啟用,,也沒有建立相關(guān)的配置文件,,因此在DEVICE 欄位里顯示的是”—”。在配置完成,,重啟網(wǎng)絡(luò)服務(wù)后就會(huì)顯示相應(yīng)的設(shè)備名,,在我的虛擬機(jī)上顯示的是“enp0s3”
2、使用nmcli命令手工配置網(wǎng)卡 需要配置的網(wǎng)絡(luò)信息:
IP地址:172.20.31.221/24 網(wǎng)關(guān):172.20.31.240 DNS:202.96.69.38
命令:
[root@localhost ~]# nmcli connection modify enp0s3 > connection.autoconnect yes > ipv4.method manual > ipv4.address 172.20.31.221/24 > ipv4.gateway 172.20.31.240 > ipv4.dns 202.96.64.68
autoconnect 是設(shè)置開機(jī)自動(dòng)連接 ipv4.method 是設(shè)置手工配置IPV4地址
重啟網(wǎng)絡(luò)服務(wù)
[root@localhost ~]# systemctl restart network
3,、查看配置后的網(wǎng)卡配置信息
[root@localhost ~]# nmcli connection show enp0s3
connection.id: enp0s3
connection.uuid: 5d58d8cc-8caf-458b-a672-ed0cdf58292e
......(中間省略)......
ipv4.method: manual
ipv4.dns: 202.96.69.38
ipv4.dns-search:
ipv4.addresses: 172.20.31.221/24
ipv4.gateway: 172.20.31.240
......(中間省略)......
IP4.地址[1]: 172.20.31.221/24
IP4.網(wǎng)關(guān): 172.20.31.240
IP4.DNS[1]: 202.96.69.38
......(以下省略)......
因?yàn)樵贑entOS7.x中取消了ifconfig命令,, 我們使用ip addr來代替。
[root@localhost ~]# ip addr
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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:ef:69:36 brd ff:ff:ff:ff:ff:ff
inet 172.20.31.221/24 brd 172.20.31.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:feef:6936/64 scope link
valid_lft forever preferred_lft forever
4,、設(shè)置雙IP
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-enp0s3 ifcfg-enp0s3:1
[root@localhost network-scripts]# vi ifcfg-enp0s3:1
將下列二項(xiàng)內(nèi)容進(jìn)行修改:
NAME=enp0s3:1
DEVICE=enp0s3:1
IPADDR=172.20.31.222
PREFIX=24
保存退出后,,生詞網(wǎng)絡(luò)服務(wù),然后查看配置信息
[root@localhost ~]# nmcli connection show enp0s3
connection.id: enp0s3
connection.uuid: 5d58d8cc-8caf-458b-a672-ed0cdf58292e
......(中間省略)......
ipv4.method: manual
ipv4.dns: 202.96.69.38
ipv4.dns-search:
ipv4.addresses: 172.20.31.221/24, 172.20.31.222/24
ipv4.gateway: 172.20.31.240
......(中間省略)......
IP4.地址[1]: 172.20.31.221/24
IP4.地址[2]: 172.20.31.222/24
IP4.網(wǎng)關(guān): 172.20.31.240
IP4.DNS[1]: 202.96.69.38
......(以下省略)......
查看全部網(wǎng)絡(luò)設(shè)備信息
[root@localhost network-scripts]# ip addr
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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:ef:69:36 brd ff:ff:ff:ff:ff:ff
inet 172.20.31.221/24 brd 172.20.31.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 172.20.31.222/24 brd 172.20.31.255 scope global secondary enp0s3:1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:feef:6936/64 scope link
valid_lft forever preferred_lft forever
在enp0s3中會(huì)出現(xiàn)二個(gè)”inet”,,包含配置過的二個(gè)IP的信息,。
5、配置hostname 使用hostnamectl來配置主機(jī)的hostname
[root@localhost network-scripts]# hostnamectl set-hostname www.cmzsteven.com
[root@localhost network-scripts]# cat /etc/hostname
www.cmzsteven.com
重新登錄后生效,。
6,、自動(dòng)獲取IP地址 如果局域網(wǎng)里有DHCP服務(wù)器,那么可以使用自動(dòng)獲取來取得主機(jī)的IP等相關(guān)信息
[root@localhost ~]# nmcli connection modify eth0 > connection.autoconnect yes > ipv4.method auto
然后重啟網(wǎng)絡(luò)服務(wù)即可,。
|