linux基礎unit11-管理網絡
unit11-管理網絡
1.ip基礎知識
ipv4:2進制32位
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
(2).文本化圖形
nmtui
<<命令>>
ifconfig 網卡 ip netmask ##臨時設定
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes
nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24
nmcli connection delete westos
nmcli connection show
nmcli connection down westos
nmcli connection up westos
nmcli connection modify "westos" ipv4.addresses newip/24
nmcli connection modify "westos" ipv4.method <auto|manual>
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
NETNASK=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
####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讀取的優先級調整
/etc/nsswitch.conf
38 #hosts: db files nisplus nis dns
39 hosts: files dns ##files代表本地解析文件,dns代表dns服務器,那個在前面那個優先
1.ip基礎知識
ipv4:2進制32位
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
(2).文本化圖形
nmtui
<<命令>>
ifconfig 網卡 ip netmask ##臨時設定
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes
nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24
nmcli connection delete westos
nmcli connection show
nmcli connection down westos
nmcli connection up westos
nmcli connection modify "westos" ipv4.addresses newip/24
nmcli connection modify "westos" ipv4.method <auto|manual>
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
NETNASK=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
####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讀取的優先級調整
/etc/nsswitch.conf
38 #hosts: db files nisplus nis dns
39 hosts: files dns ##files代表本地解析文件,dns代表dns服務器,那個在前面那個優先
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.