1. 程式人生 > >linux基礎學習 管理網絡

linux基礎學習 管理網絡

linux 網絡管理

一.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位為主機位


二.配置ip


<<圖形化>>


1.圖形界面


nm-connection-editor


技術分享


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 ##子網掩碼


三.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


技術分享


四.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服務器,那個在前面那個優先










linux基礎學習 管理網絡