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的方式

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 ifcfg-xxx            ###网络配置文件格式

DEVICE=eth0              ##指定文件管理的设备名称

BOOTPROTO=dhcp            ##dhcp动态获取,none和static都表示静态网络

ONBOOT=yes                ##开机自动激活设备

NAME=hello                ##指定网络链接的名字为hello

 

###静态网络配置###

vim 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##################

网关就是路由器上和我们的主机处在同一个网段上的ip

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

GATEWAY=网关地址

 

 

 

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

1.ip映射文件

/etc/hosts

ip主机名称

 

 

 

 

2.dns服务器的指向文件

vim /etc/resolv.conf

nameserver 172.25.254.254

 

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

DNS1=172.25.254.254

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

 

 

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