第十一單元總結

###########################################

#################第十一單元##################

#############################################

1.網絡基礎知識

一臺主機如果可以連接公網,比如訪問www.baidu.com

那麼這臺主機必然會有

ipaddress

GATEWAY

dns

############ipaddress##############

tcp/ip

ipv4

2進制32位

254.254.254.254/255.255.255.0

11111110.11111110.11111110.11111110/11111111.11111111.11111111.00000000

 

254.254.0.254/255.255.255.0

254.254.0.254/255.255.0.0

 

########ip設定###########

ifconfig                                 ###查看或者臨時設定主機ip的工具

 

ifconfig 網絡接口                        ##查看這個接口上的 ip

 

ifconfig 網絡接口 ip netmask 子網掩碼    ####臨時設定ip

ifconfig eth0 172.25.254.100 netmask 255.255.255.0

 

 

systemctl restart network                ###重新啓動網絡基本服務

systemctl restart NetworkManager         ###網絡智能管理服務

 

圖形網絡配置方式

nm-connection-editor                       ##圖形中的網絡設定工具

nmtui                                      ##文本中的網絡設定工具

 

命令設定ip的方式

ifconfig 網卡 ip nermask         ##臨時設定

nmcli

nmcli connection delete連接名稱                                                         ###刪除此連接

nmcli connection add con-name westos ifname eth0 type ethernet autoconnect  yes         ####添加動態網絡

nmcli connection add con-name westos ifname eth0 type ethernet ip4 ip/24 gw4 ip         ###靜態網絡

 

網絡配置文件

/etc/sysconfig/network-scripts/                ###網絡配置目錄

 

###動態網絡配置###

vim /etc/sysconfig/network-scripts/ifcfg-xxx                     ###網絡配置文件格式

DEVICE=eth0                       ##指定文件管理的設備名稱

BOOTPROTO=dhcp                    ##dhcp動態獲取,none和static都表示靜態網絡

ONBOOT=yes                        ##開機自動激活設備

NAME=hello                        ##指定網絡鏈接的名字爲hello

 

###靜態網絡配置###

vim /etc/sysconfig/network-scripts/ifcfg-xxx                            ###網絡配置文件格式

DEVICE=eth0                             ##指定文件管理的設備名稱

BOOTPROTO=static|none##dhcp動態獲取,none和static都表示靜態網絡

ONBOOT=yes                              ##開機自動激活設備

NAME=hello                              ##指定鏈接名字

IPADDR=172.25.254.100                   ##設定ip爲172.25.254.100

NETMASK=255.255.255.0                   ##子網掩碼爲255.255.255.0

PREFIX=24                               ##子網掩碼爲255.255.255.0

 

 

 

 

####################網關gateway##################

1.路由器

主要功能是用來作nat的

dnat    目的地地址轉換

snat    源地址轉換


2.網關

就是路由器上和我們的主機處在同一個網段上的ip


3.設定網關

systemctl stop  NetworkManager

vim /etc/sysconfig/network                      ##全局網關

GATEWAY=網關ip


vim /etc/sysconfig/network-scripts/ifcfg-xxx(網卡配置文件) ##網卡接口網關

GATEWAY=網關ip

systemctl restart network


rout -n                      ##查詢網關

Kernel IP routing table

wKiom1gGMZ3Rvw28AAC5tcJf8zc060.png-wh_50 

 

####################域名解析####################

  1. dns

dns是一臺服務器

這臺服務器提供了回答客戶主機名和ip對應關係的功能


2.dns服務器的指向文件

vim /etc/resolv.conf

nameserver dns服務器ip (172.25.254.254)

 

vim /etc/sysconfig/network-scripts/ifcfg-xxx

DNS1=dns服務器ip (172.25.254.254)

PEERDNS=yes|no                            ###配置文件是否會修改/etc/resolv.conf no表示不修改

 

3.本地解析文件

vim /etc/hosts

ip     主機名稱


4.本地解析文件和dns讀取的優先級調整

/etc/nsswitch.conf

 38 #hosts:       db files nisplus nis dns 

 39 hosts:        files dns             #files代表本地解析文件,dns代表dns服務器,哪個在前哪個優先


nmcli device show

nmcli device status

nmcli device disconnect eth0

nmcli device connect eth0

nmcli connection edit "System westos1"

nmcli connection modify "System westos1"  ipv4.addresses 172.25.254.101/24

nmcli connection modify "System westos1"  ipv4.dns 172.25.254.1

nmcli connection modify  "System westos1" ipv4.method auto

nmcli connection modify "System westos1" ipv4.method manual

nmcli connection delete "System westos1"

nmcli connection add con-name eth0 ifname eth0  type ethernet ip4 172.25.254.100 gw4 172.25.254.254

nmcli connection modify eth0 ipv4.dns 172.25.254.254

 

 

################網絡端口的檢測#######################

ss|netstat

-a             ##所有

-n             ##不做解析

-t             ##tcp協議

-u             ##udp協議

-l             ##listen,當前活躍端口

-e             ##顯示端口的詳細信息

 

/etc/service    ##系統服務默認使用端口信息文件


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章