標籤:ip地址 linux 基礎知識 網路 網卡
Unit11.管理網路
1.ip基礎知識
1.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
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
650) this.width=650;" src="https://s4.51cto.com/wyfs02/M00/90/1B/wKiom1jvL9zBfFtEAAAsHnXukkc884.jpg" title="36020170413155740637.jpg" alt="wKiom1jvL9zBfFtEAAAsHnXukkc884.jpg" />
<<檔案>>
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 ##子網路遮罩
650) this.width=650;" src="https://s4.51cto.com/wyfs02/M00/90/1A/wKioL1jvL9HSTwheAAAyxDROwC4501.jpg" title="36020170413155752310.jpg" alt="wKioL1jvL9HSTwheAAAyxDROwC4501.jpg" />
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
650) this.width=650;" src="https://s1.51cto.com/wyfs02/M01/90/1B/wKiom1jvL-rBsr_bAAAaPdhG5h0986.jpg" title="36020170413155824055.jpg" alt="wKiom1jvL-rBsr_bAAAaPdhG5h0986.jpg" />
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伺服器,那個在前面那個優先
5.dhcp服務的配置
Linux學習 Unit 11