第十一单元总结

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

#################第十一单元##################

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

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    ##系统服务默认使用端口信息文件


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