12.Linux-网络配置(一)

mac2024-03-31  29

ip基础知识

1.ipv4 2进制32位-----10进制 172.25.0.10/255.255.255.0 172.25.0.10:ip地址 255.255.255.0:子网掩码 子网掩码255位对应的ip位为网络位 子网掩码0对应的ip位为主机位

ping

ping ip ###检测网络是否畅通 ping -c1 ip ###ping1次 ping -w1 ip ###等待1秒 ping -c1 -w1 ip ###ping1次等待1秒

ifconfig

ifconfig device ip/mask 设定某个设备的网络接口ip地址 ifconfig device down 关闭某个设备的网络接口 ifconfig device up 开启某个设备网络接口

ip addr

ip addr show 检测设备的网络接口 ip addr add ip/mask dev device 设定某个设备的接口ip ip addr del dev device ip/mask 删除某个设备的指定网络接口ip

管理网络配置文件

网络配置的目录 /etc/sysconfig/network-scripts/

文本化图形设置ip

输入nmtui

图形界面设置ip

nm-connection-editor

命令方式设定ip

1.nmcli device show device 显示设备的相关信息 nmcli device show 显示所有设备的相关信息 nmcli device connect device 启用相关设备 nmcli device disconnect device 关闭相关设备 nmcli device status device 查看相关设备的状态信息

2.nmcli connection show 显示已经连接的设备信息 nmcli connection down westos 关闭已经连接的westos nmcli connection up westos 打开westos设备 nmcli connection delete westos 删除westos设备信息 nmcli connection delete uuid 删除相关设备信息 nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/mask 设置一个静态网络

动态网络设定

vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp

systemctl restart network

静态网络设定

vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes IPADDR=172.25.20.120 NETMASK=255.255.255.0 BOOTPROTO=none/static NAME=eth0

systemctl restart network

路由器

路由器原理 开启desktop的内核路由功能: 使用sysctl -p命令使设定生效: 打开地址伪装功能,(desktop上操作),使真实主机变为路由器:

firewall-cmd --list-all 查看防火墙下的相关信息 firewall-cmd --permanent --add-masquerade命令开启防火墙的伪装功能 firewall-cmd --reload命令重新加载防火墙的配置 在server上设置网关:(网关,路由器上和自己处在同一个网段的那个ip) systemctl stop NetwrokManager vim /etc/sysconfig/network ##全局网关 GATEWAY=网关ip

vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件 ##网卡接口网关 GATEWAY=网关ip

systemctl restart netwrok

检验路由器的内核路由功能,用server这台主机远程连接172.25.154.60这台真机 以下是设置路由器前后的实验结果:

最新回复(0)