nmcli connection add type ethernet con-name westos ifname ens160 ip4 192.168.31.239/24
#更改
nmcli connection modify westos ipv4.addresses 192.168.31.109/24
####7.管理网络配置文件
网络配置目录
/etc/sysconfig/network-scripts/
网络配置文件的名命规则
ifcfg-xxxx
DEVICE=xxx ##设备名称
BOOTPROTO=dhcp|static|none ##设备工作方式
ONBOOT=yes ##网络服务开启时自动激活网卡
IPADDR= ##IP地址
PREFIX=24 ##子网掩码
NETMASK=255.255.255.0 ##子网掩码
NAME= ##接口名称
dhcp网络设定
vim /etc/sysconfig/network-scripts/ifcfg-enp1s0
DEVICE=enp1s0
ONBOOT=yes
BOOTPROTO=dhcp
nmcli connection reload
nmcli connection down enp1s0
nmcli connection up enp1s0
示例:
静态网络设定文件
vim /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE=enp1s0
ONBOOT=yes
IPADDR=172.25.254.101
NETMASK=255.255.255.0
BOOTPROTO=none
NAME=enp1s0
注意:编辑过网络配置文件之后需要重启网络
nmcli connection reload
nmcli connection down enp1s0
nmcli connection up enp1s0
一块网卡上配置多个IP
vim /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE=enp1s0
ONBOOT=yes
IPADDR0=172.25.254.101
NETMASK0=255.255.255.0
BOOTPROTO=none
NAME=westos
IPADDR1=1.1.1.101
PREFIX1=24
重启网络
nmcli connection reload
nmcli connection down enp1s0
nmcli connection up enp1s0
ip addr show ens160
####8.lo回环接口
回环接口------人的神经----127.0.0.1-----localhost
####9.网关#####
1.把双网卡主机localhost2变成路由器
***单网卡主机ip1.1.1.101***
***双网卡主机ip1.1.1.201,ip172.25.254.201****
***真机ip172.25.254.1***
(设置双网卡主机)
systemctl start firewalld
firewall-cmd --list
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload
firewall-cmd --list-all
public (default, active)
interfaces: br0 enp0s25 wlp3s0
sources:
services: dhcpv6-client ssh
ports:
masquerade: yes <<<地址伪装功能开启,真实主机变成路由器
forward-ports:
icmp-blocks:
rich rules:
sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
给单网卡主机添加双网卡的网关
ip route add default via 1.1.1.201
测试:当单网卡的主机可以ping 通172.25.254.1主机时说明路由成功
2.设定单网卡主机localhost1的网关
vim /etc/sysconfig/network ##全局网关,针对所有没有设定网关的网卡生效
GATEWAY=1.1.1.201
vim /etc/sysconfig/network-scripts/ifcfg-enp1s0
GATEWAY0=1.1.1.201 ##当网卡中设定的IP有多个时,指定对于那个IP生效
GATEWAY=1.1.1.201 ##当网卡中设定的IP只有一个时
route -n ##查看网关
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 1.1.1.201 0.0.0.0 UG 0 0 0 enp1s0
1.1.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp1s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
##10.设定dns
#地址解析
#系统操作者对字符敏感
#系统网络通信需要通过ip地址这个数字
#当操作着输入网址www.baidu.com,这个网址不是一个可以通信的IP地址
#于是必须要在系统中把www.baidu.com变成百度服务器的IP地址
#这样的过程叫做地址解析
domain name server == 域名解析服务 ##解析就是把域名变成IP
vim /etc/hosts ##本地解析文件,此文件中直接提供地址解析
ip 域名
14.215.177.38 www.baidu.com
123.151.137.18 www.qq.com
vim /etc/resolv.conf ##dns的指向文件 不需要重新启动网络立即生效
nameserver 114.114.114.114 ##当需要某个域名的IP地址时去问114.114.114.114
vim /etc/sysconfig/network-scripts/ifcfg-xxxx
DNS1=114.114.114.114 ##需要重启网络,当网络重新启动
##此参数会修改/etc/resolv.conf
注意:
当网络工作模式为dhcp时‘4302
系统会自动获得ip 网关 dns
那么/etc/resolv.conf会被获得到的信息修改
如果不需要获得dns信息
在网卡配置文件中加入
PREEDNS=no
##11.设定解析的优先级
系统默认:
/etc/hosts > /etc/resolv.conf
vim /etc/nsswitch.conf
39 hosts: files dns ##/etc/hosts优先
vim /etc/nsswitch.conf
39 hosts: dns files ##/etc/resolv.conf dns指向优先
####12.dhcp服务配置
在主机中使用景象找到dhcp-server的安装包
rpm -ivh dhcp-server
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf ##用模板生成配置文件
vim /etc/dhcp/dhcpd.conf
dhcpd.conf
Sample configuration file for ISC dhcpd
option definitions common to all supported networks…
option domain-name “westos.com”; ##域名
option domain-name-servers 114.114.114.114; ##dns
default-lease-time 600; ##默认租约
max-lease-time 7200; ##最长租约
Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
If this DHCP server is the official DHCP server for the local
network, the authoritative directive should be uncommented.
#authoritative;
#Use this to send dhcp log messages to a different log file (you also
have to hack syslog.conf to complete the redirection).
log-facility local7;
No service will be given on this subnet, but declaring it helps the
DHCP server to understand the network topology.
27 删除
28 删除
This is a very basic subnet declaration.
subnet 172.25.254.0 netmask 255.255.255.0 { ##子网设定
range 172.25.254.160 172.25.254.200; ##IP地址池
option routers 172.25.254.250; ##网关
}
35行后全删除
systemctl restart dhcpd
systemctl stop firewalld
测试:
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!
详情docs.qq.com/doc/DSmdCdUNwcEJDTXFK
zZG4ubmV0L1N1bl9fcw==,size_16,color_FFFFFF,t_70)
测试:
[外链图片转存中…(img-ute0K3qu-1724259039600)]
[外链图片转存中…(img-J7VCySjB-1724259039601)]
[外链图片转存中…(img-HemBAJzR-1724259039601)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!
详情docs.qq.com/doc/DSmdCdUNwcEJDTXFK