1. 程式人生 > >linux配置ip子網dns

linux配置ip子網dns

1)從命令列將Linux主機重啟
# reboot
2)從命令列將Linux主機關機
# poweroff



.配置網路
# ifconfig 檢視當前網路資訊(IP地址、子網掩碼)
# route -n 檢視閘道器
# cat /etc/resolv.conf 檢視dns地址
# hostnamectl 檢視主機名

圖形配置網路
Alt+F2
nm-connection-editor
右上角把網路重新啟用
驗證
hostnamectl -sethostname xxx.xxx.xxx
[[email protected] ~]# hostnamectl
[[email protected] ~]# hostnamectl set-hostname teacher.tedu.cn
[

[email protected] ~]# hostnamectl
Static hostname: teacher.tedu.cn
Icon name: computer-vm
Chassis: vm
Machine ID: d3f0970c5308449d950e3453c9a449ba
Boot ID: c5799a77789d47ca9a670064a03655eb
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64

命令配置網路
# nmcli device status 列出所有的網絡卡裝置
# nmcli connection show 列出已配置的網路連線
手動設定IP地址/掩碼,允許自動連線
nmcli con mod "連線名" ipv4.method manual ipv4.address "IP地址/掩碼位數"
# nmcli connection modify eth0 ipv4.method manual ipv4.addresses "10.0.0.10/255.255.255.0"

nmcli con mod "連線名" connection.autoconnect yes
# nmcli connection modify eth0 connection.autoconnect yes

手動指定預設閘道器、DNS地址
# nmcli con mod "連線名" ipv4.gateway 預設閘道器地址
# nmcli con mod "連線名" ipv4.dns DNS地址
# nmcli connection modify eth0 ipv4.gateway 10.0.0.254
# nmcli connection modify eth0 ipv4.dns 4.4.4.4

停用指定連線
nmcli con down "連線名"
啟用指定連線
nmcli con up "連線名"

# nmcli connection down eth0
# nmcli connection up eth0
# ifconfig *
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.10 netmask 255.255.255.0 broadcast 10.0.0.255

route -n

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.254 0.0.0.0 UG 100 0 0 eno16777736

cat /etc/resolv.conf

Generated by NetworkManager

search tedu.cn
nameserver 4.4.4.4