##################1.网络基础知识

(1)一台主机如果可以连接公网比如访问www.baidu.com,那么这台主机必然会有

Ipaddress    

GATEWAY    

dns

(2)Ipaddress

 ipv4

2进制32位-----10进制

 

172.25.0.10/255.255.255.0

11111110.11111110.11111110.11111110/11111111.11111111.11111111.00000000

172.25.0.10ip地址

255.255.255.0子网掩码

子网掩码255位对应的ip位为网络位

子网掩码0对应的ip位为主机位

 

##################2.ip的设定

 

ifconfig###查看或者临时设定主机ip的工具(同ip  addr  show)

ifconfig 网络接口##查看这个接口上的 ip

 

systemctl restart network###重新启动网络基本服务

systemctl restart NetworkManager###网络智能管理服务

 

1图形中网络设定方式(永久设定)

nm-connection-editor##图形中的网络设定工具

nmtui##文本中的网络设定工具

 网络

网络

 

 

 

 

2ifconfig临时设定

 

ifconfig 网络接口 ip netmask 子网掩码####临时设定ip

ifconfig eth0 172.25.254.100 netmask 255.255.255.0

 

(3)nmcli命令设定ip不会随重启服务或电脑而发生变化

nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes  ####添加动态网络

nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24 ##3添加静态网络

nmcli connection delete westos      westos表示链接名称###删除此链接       

nmcli connection show

nmcli connection down westos

nmcli connection up westos

nmcli connection modify "westos" ipv4.addresses newip/24

nmcli connection modify "westos" ipv4.method <auto|manual>

nmcli device connect eth0

nmcli device disconnect eth0            ###断开网的连接

nmcli device show

nmcli device status

 

(4)通过配置文件重启服务来配置地址

 

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

NETNASK=255.255.255.0 | PREFIX=24 ##子网掩码

 

############3.getway

 

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

 

rout -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

 

##################4.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服务器那个在前面那个优先

 

5.dhcp配置文件

yum install dhcp -y

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example   /etc/dhcp/dhcpd

vim /etc/dhcp/dhcpd

 网络

 

 

 

删除27行

 

systemctl start dhcpd