网络设定
常用网络协议ipv4,32位  2进制
111111110.11111110.11111110.11111110==254.254.254.254

1.neymask
用来标实ip的网络位和主机位
网络位表示网络区域
主机位表示网络区域中的某台主机
netmask非0位所对应的ip地址数值为这个ip的网络位
neymask0位所对应的ip地址数值为这个ip的主机位
网络位一致主机位不一致的两个ip是可以直接通信的
这样的两台主机叫做直连网络

2.网络设置
1)方法一:ifconfig 网络名称 ip netmask 子网掩码   #临时改ip,网络服务重启后失效
  网络设定及路由搭建
2)方法二:nm-connection-editor
dhcp    动态获取,ip不固定
static  静态ip为操作者自行设定
在此图形工具中选择dhcp为动态网络

在此图形工具中选择manual为静态网络,ip须自行手动输入

网络设定及路由搭建


nmtui   #当系统没有图形时可以用此命令开启网络设定的ui界面,添加不需要重启,更改需要重启

网络设定及路由搭建

3)方法三:nmcli

nmcli device status eth0        #显示状态

网络设定及路由搭建

nmcli device disconnect eth0    #关闭

网络设定及路由搭建

nmcli device show eth0          #显示详细信息

nmcli device connect eth0       #打开

网络设定及路由搭建


nmcli connection down     链接名   #关闭连接
nmcli connection up          链接名   #开启连接
nmcli connection delete    链接名   #删除链接
nmcli connection show     链接名   

nmcli connection add type ethernet con-name 链接名 ifname eth0 autoconnect yes   #添加动态ip

网络设定及路由搭建

nmcli connection add type ethernet con-name 链接名 ifname eth0 ip4 172.25.254.252/24   #添加静态ip

网络设定及路由搭建


static--->dhcp   #静态改为动态

nmcli connection modify lin ipv4.method auto

网络设定及路由搭建

dhcp---->static  #动态改为静态

nmcli connection modify lin ipv4.adresses 172.25.254.252/24

nmcli connection modify lin ipv4.method manual

网络设定及路由搭建


改ip
nmcli connection modify lin ipv4.adresses 172.25.254.140/24
每次修改完需要重启网络
4)方法四:cd /etc/sysconfig/network-scripts/
vim ifcfg-xxxx
DEVICE=网卡    
ONBOOT=yes
BOOTPROTO=dhcp|none|static
IPADDR=ip
NETMASK=子网掩码|PREFIX=子网掩码缩写

NAME=xxx        #可写可不写

添加动态ip

cd /etc/sysconfig/network-scripts/
vim ifcfg-xxxx
DEVICE=网卡    
ONBOOT=yes

BOOTPROTO=dhcp

NAME=xxx

网络设定及路由搭建

添加静态ip

cd /etc/sysconfig/network-scripts/
vim ifcfg-xxxx
DEVICE=网卡    
ONBOOT=yes
BOOTPROTO=none|static
IPADDR=ip
NETMASK=子网掩码|PREFIX=子网掩码缩写

NAME=xxx        #可写可不写

网络设定及路由搭建

添加多个ip

网络设定及路由搭建

3.网关
cd /etc/sysconfig/network-scripts/
vim ifcfg-xxx

GATEWAY=172.25.254.155

网络设定及路由搭建


4.设置DNS解析

网址变成ip  #地址解析

vim /etc/resolv.conf

 nameserver  114.114.114.114

  网络设定及路由搭建

测试

网络设定及路由搭建

vim /etc/hosts 本地解析

网络设定及路由搭建

测试

网络设定及路由搭建

5.设置主机为路由器
主机:
     route -n

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

    网络设定及路由搭建

    systemctl restart network
    route -n
    ping www.baidu.com
    systemctl start firewalld
    firewall-cmd --add-masquerade
    firewall-cmd --list-all

    ifconfig

网络设定及路由搭建

网络设定及路由搭建

虚拟机:vim ifcfg-xxx

GATEWAY=主机ip

网络设定及路由搭建

虚拟机里测试

网络设定及路由搭建


排错:虚拟机网卡
virt-manager

路由器内核
   1)  sysctl -a | grep ip_forward
   2)  vim /etc/sysctl.conf
   net.ipv4.ip_forward = 1
   3)  sysctl -p
 

相关文章:

  • 2021-12-15
  • 2021-08-06
  • 2022-12-23
  • 2021-06-11
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2021-08-20
  • 2021-12-06
  • 2021-04-24
  • 2021-06-17
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案