ipv4 : 2進制32位-----10進制
172.25.0.10/255.255.255.0
172.25.0.10: ip地址
255.255.255.0: 子網掩碼
子網掩碼255位對應的ip位爲網絡位,子網掩碼0對應的ip位爲主機位
2.配置ip
<<圖形化>>
1)圖形界面
nm-connection-editor
a.先刪除原有ip
b.add添加ip(選擇Ethernet)
address選擇eth0
c.點擊ipv4,add添加ip(如圖所示)
2)文本化圖形
nmtui
方法同上
<<命令>>
ifconfig 網卡 ip netmask ##臨時設定
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes #添加dhcp網絡
nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24 #添加靜態網絡
nmcli connection delete westos #刪除westos鏈接
nmcli connection show #顯示所有網絡鏈接
nmcli connection down westos #關閉指定鏈接
nmcli connection up westos #開啓指定鏈接
nmcli connection modify "westos" ipv4.addresses newip/24 #改變wetos的ip
nmcli connection modify "westos" ipv4.method <auto|manual> #改變westos的工作方式爲動態或者靜態
nmcli device connect eth0 #開啓設備
nmcli device disconnect eth0 #關閉設備
nmcli device show #顯示設備信息
nmcli device status #顯示設備狀態
<<文件>>
dhcp ##動態獲取
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 ##接口使用設備
BOOTPROTO=dhcp ##網卡工作模式
ONBOOT=yes ##網絡服務開啓時自動激活
NAME=eth0 ##網絡接口名稱
:wq
systemctl restart network
static|none ##靜態網絡
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 ##設備
BOOTPROTO=static|none ##設備工作方式
ONBOOT=yes ##開啓網絡服務激活設備
NAME=eth0 ##網絡接口名稱
IPADDR=172.25.0.100 ##IP
NETMASK=255.255.255.0 | PREFIX=24 ##子網掩碼
3.gateway 網關
1)路由器
主要功能是用來作nat的
dnat 目的地地址轉換
snat 源地址轉換
2)網關
路由器上和自己處在同一個網段的那個ip
3)設定網關
systemctl stop NetwrokManager
vim /etc/sysconfig/network ##全局網關
GATEWAY=網關ip
vim /etc/sysconfig/network-scripts/ifcfg-網卡配置文件 ##網卡接口網關
GATEWAY=網關ip
systemctl restart netwrok
route -n ##查詢網關
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 (網關)172.25.0.254 0.0.0.0 UG 0 0 0 eth0
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
######linux主機連wifi########
1.打開配置文件
vim /etc/sysconfig/network-scripts/ifcfg-網卡配置文件
2.刪除文件中GATEWAY0這一行。
配置完後重啓:systemctl restart network
3.給電腦連wifi
4.檢查網絡是否可用
上圖所示連接成功
#######虛擬機連網#######
1.主機的設置
在root用戶下:
先查看/etc/resolv.conf
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --permanent --add-masquerade
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.43.1 masquerade'
2.虛擬機的設置
1)配置網關文件
vim /etc/sysconfig/network
添加:
GATEWAY=網關ip
重置:
systemctl restart netwrok
2)vim /etc/resolv.conf
添加:
nameserver 192.168.43.1
意外情況:該虛擬機網卡已壞,需重新添加
在主機root用戶下:
virt-manager
點開所要連網的虛擬機
點擊燈泡圖形,刪除壞網卡
添加新網卡:按如圖所示操作
結果:
5.dns
1)dns
dns是一臺服務器
這太服務器提供了回答客戶主機名和ip對應關係的功能
2)設定dns
vim /etc/resolv.conf
nameserver dns服務器ip
vim /etc/sysconfig/network-scripts/ifcfg-網卡配置文件
DNS1=dns服務器ip
3)本地解析文件
vim /etc/hosts
ip 主機名稱
4)本地解析文件和dns讀取的優先級調整
vim /etc/nsswitch.conf
38 #hosts: db files nisplus nis dns
39 hosts: files dns ##files代表本地解析文件,dns代表dns服務器,那個在前面那個優先