linux菜鳥基礎學習 (六) 網路
阿新 • • 發佈:2018-11-09
linux下的網路配置
1.什麼是IP ADDRESS
internet protocol ADDRESS ##網路協議地址
ipv4 internet protocol version 4
1.2x32
ip是由32個0和1組成
11111110.11111110.11111110.11111110 = 254.254.254.254
2.子網掩碼
用來劃分網路區域
子網掩碼非0的位對應的ip上的數字表示這個ip的網路位
子網掩碼0位對應的數字是ip的主機位
網路位表示網路區域
主機位表示網路區域裡的某臺主機
3.ip通訊判定
網路位一致,主機位不一致的兩個IP可以直接通訊 172.25.254.1/24 24=255.255.255.0 172.25.254.2/24 172.25.0.1/16
4.網路設定工具
ping ##檢測網路是否通暢
ifconfig ##檢視或設定網路介面
ifconfig device ip/24 ##設定網路
ifconfig device down ##關閉
ifconfig device up ##開啟
5.圖形方式設定ip
1.nm-connection-editor
2.nmtui
6.命令方式設定網路
nmcli nmcli device connect eth0 ##啟用eth0網絡卡 nmcli device disconnect eth0 ##關閉eth0網絡卡 nmcli device show eth0 ##檢視網絡卡資訊 nmcli device status eth0 ##檢視網絡卡服務介面資訊 nmcli connection show nmcli connection down westos nmcli connection up westos nmcli connection delete westos nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.100/24 nmcli connection modify westos ipv4.method auto nmcli connection modify westos ipv4.method manual nmcli connection modify westos ipv4.addresses 172.25.254.150/24
7.管理網路配置檔案
網路配置目錄 /etc/sysconfig/network-scripts 網路配置檔案的命名規則 ifcfg-xxx DEVICE=xxx ##裝置名稱 BOOTPROTO=dhcp|static|none ##裝置的工作方式 ONBOOT=yes ##網路服務開啟時自動啟用網絡卡 IPADDR= ##IP地址 PREFIX=24 ##子網掩碼 NETMASK=255.255.255.0 ##子網掩碼 示例: 靜態網路設定檔案 vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes IPADDR=172.25.254.100 NETMASK=255.255.255.0 BOOTPROTO=none NAME=westos systemctl restart network
一塊網絡卡上配置多個IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR0=172.25.254.100
NETMASK0=255.255.255.0
BOOTPROTO=none
NAME=westos
IPADDR1=172.25.0.100
PREFIX1=24
systemctl restart network
ip addr show eth0
8.lo迴環介面
9.閘道器
1.把真實主機變成路由器
firewall-cmd --list-all
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload
2.設定虛擬機器閘道器
vim /etc/sysconfig/network
GATEWAY=172.25.254.250
10.設定dns
doamin name system
vim /etc/hosts ##本地解析檔案
ip 域名
61.135.169.121 www.baidu.com
vim /etc/resolv.conf ##dns指向檔案
nameserver 114.114.114.114
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=114.114.114.114
11.設定解析優先順序
系統預設
/etc/hosts > /etc/resolv.conf
vim /etc/nsswitch.conf
39 hosts: files dns ##/etc/hosts優先
vim /etc/nsswitch.conf
39 hosts: dns files ##/etc/resolv.conf優先