1.#####什么是IP ADDRESS#######
internet protocol ADDRESS ##网络进程地址
ipv4 internet protocol version 4
2X32 ------>ip由32个01组合组成
111111110.11111110.11111110.11111110=254.254.254.254

<区域(前24位,8位为一组)> <主机位>

2.#######子网掩码#######
用来划分网络区域
子网掩码非0位对应的ip上的数字表示这个ip的网络位
子网掩码0位对应的数字是ip的主机位
网络位表示网络区域
主机位表示网络区域里的某台主机
3.#######ip通信判定#######
网络位一致,主机位不一致的2个IP可以直接通讯
172.25.254.1/24 24=255.255.255.0 //前24位为网络位1表示为第一台主机
172.25.254.2/24 // 前24位为网络位1表示为第一台主机
172.25.0.1/16 16=255.255.0.0 //前16位为网络位1表示为第一台主机

A类地址:172.25.254.0/8(第一位是网络位)
B类地址:172.25.254.0/16(前俩位为网络位)
C类地址:172.25.254.0/24(前三位是网络位)

4.#####网络设定工具#######
(1)

ping ##检测网络是否通畅
ping -c 1 -w 1 ##-c(次数) -w(时间)


(2)

ifconfig ##查看或设定网络接口



ifconfig device ip/24 ##设定ip为临时设定



ifconfig device down ##关闭网卡



ifconfig device up ##开启网卡


(3)

ip addr ##检测这项网络接口



ip addr show ##检测


ip addr add ip/24 dev device ##设定

更改ip步骤
ip addr flush eth0
ip addr add ip/24 dev device



注意:device的名字是一个物理事实,看到什么名字只能用什么名字
5.图形方式设定ip
(1)

nm-connection-editor ##修改后不生效



(2)

systemctl stop NetworkManager //关闭NetworkManager服务
systemctl restart network //重启网络
systemctl start NetworkManager //开启NetworkManager服务



(3)nmtui
6.命令方式设定网络

nmcli ##NetworkManager必须开启

(1)使用设备名称


nmcli device connect eth0 ##启用eth0网卡
nmcli device disconnect eth0 ##关闭eth0网卡
nmcli device show eth0 ##查看网卡信息



nmcli device status eth0 ##查看网卡服务接口信息


(2)使用网络名称

nmcli connection show //显示网络信息
nmcli connection down eth0 //关闭
nmcli connection up eth0 //开启
nmcli connection delete eth0 //删除



nmcli connection add type ethernet con-name westos ifname eth0 ip4
//添加一个名字为westos,ip为172.25.254.102/24的网



nmcli connection modify westos ipv4.method auto //修改为动态的网络



nmcli connection modify westos ipv4.method manual //修改为静态的网络

nmcli connection modify westos ipv.4 addresses 172.25.254.202/24 //修改网络ip

7.管理网络配置文件
(1)网络配置目录
/etc/sysconfig/network-scripts
(2)网络配置文件的命名规则
ifcfg-xxxx

DEVICE=**** //设备名称
BOOTPROTO=dhcp/static/none //设备工作方式(静态/动态/无)
ONBOOT=yes //网络服务开启时自动激活网卡
IPADDR=yes //ip地址
PREFIX=24 //子网掩码设置形式1
NETMASK=255.255.255.0 //子网掩码设置形式2
NAME=eth0 //接口名称
TYPE=Ethernet //网卡工作模式(以太网)

<动态的网络设定>:只能指定一个
vim /etc/sysconfig/network-scripts/ifconfig-zll


<静态的网络设定>:可以设定多个
vim /etc/sysconfig/network-scripts/ifconfig-westos
<一块网卡上配置多个ip>
8.网关
路由器:为一个中介,可以对ip进行转换,使俩个区域网不通的ip连网
网关:路由器上和主机处于同一个区域网的ip地址
######模拟路由器######
1.在客户端
更改客户端ip为1.1.1.102

2.server端为路由器端:添加俩个网卡
设置俩个ip
eth0:1.1.1.202
eth1:172.25.254.202

3.在路由端也就是双网卡端

sysctl -a | grep ip_forward ##查看内核路由功能是否开启,内核的路由功能负责网路转换


(1)如果内核路由功能打开
net.ipv4.ip_forward=1
(2)如果内核路由功能没有打开
net.ipv4.ip_forward=0
解决:

vim /etc/sysctl.conf ##写入:net.ipv4.ip_forward=1
sysctl -p //生效



4.路由端:开启临时防火墙伪装 <火墙必须是开启的>

systemctl start firewalld //开启火墙
firewalld-cmd -add-masquerade //伪装防火墙


5.在客户端设置网关
法一:vim /etc/sysconfig/network-scripts/ifcfg-eth0 //设置单独网卡的网关



法二:vim /etc/sysconfig/network //设置全局网关,对所有网卡都生效,访问外网时将所有的数据包都扔给这个网关



systemctl restart network //设定好后要记得重启网络

route -n //查看路由

6.ping 172.25.254.250 ##在客户端检测网络是否通畅


7.traceroute 172.25.254.250 ##跟踪客户端访问175.25.254.202的过程


#######虚拟机上网###########
(1)在真机
连接网络后切换到root用户查看路由功能
(2)ip addr show br0 ##第一个是访问外网的ip,第二个是内网的ip


sysctl -a |grep ip_forward //查看内核路由功能是否开启
systemctl start firewalld //打开防火墙
firewall-cmd --add-masquerade //伪装防火墙
ping www.baidu.com <http://www.baidu.com> //查看网络是否通




(3)在客户端
vim /etc/sysconfig/network-scripts/ifcfg-eth0
//把客户端ip该为172.25.254.102 <https://xn--ip172-fq1hv41ff7lkvau56qy8xb.25.254.102>


vim /etc/sysconfig/network ## 将客户端的网关设置为真机的内网ip
systemctl restart network



(4)在客户端
在真机:ping www.baidu.com <http://www.baidu.com>

在客户端:打开火狐浏览器ping真机中的百度的ip

在浏览器中输入www.baidu.com发现无法ping通


9.域名解析
DNS(域名系统):用作域名和地址ip的相互对应,让用户能更方便的访问。
DNS服务器:专门作地址解析
(1)本地解析文件

vim /etc/hosts //即改即生效,优先级高。




(2)网络解析

vim /etc/resolv.conf //即改即生效
修改内容:添加 nameserver 114.114.114.114 //里面有基本上能用到的地址域名解析




(3)在网络配置文件中解析

vim /etc/sysconfig/network-scripts/ifcfg-westos //添加:DNS1=114.114.114.114
systemctl restart network //重启网络



(4)更改优先级

vim /etc/nsswitch.conf //改了就生效

39 hosts: dns files //默认法files的优先级高,也就是本地解析的优先级高

(5)由于在reboot系统时dns的设置会还原,网络会重启PEERDNS
PEERDNS固定dns
解决:
《1》将设备的工作方式改为动态,操作后保存退出重其网络
vim /etc/sysconfig/network-scripts/ifcfg-eth0
systemctl restart network
《2》vim /etc/resolv.conf //输入一个DNS的ip,退出保存
《3》重启动网络后查看,刚刚输入的内容被改变,系统分配了dns的ip
systemctl restart network
cat /etc/resolv.conf
《4》vim /etc/sysconfig/network-scripts/ifcfg-westos //在文件里面添加:PEERDNS=no,退出保存
《5》vim /etc/resolv.conf //输入:nameserver 114.114.114.114退出保存
重其网络后查看/etc/resolv.conf发现内容没有改变

友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信