1.什么是IP ADDRESS
internet protocol ADDRESS 网络进程地址
ipv4 internet protocol version 4
【1】2×32
ip是由32个01组成
11111110.11111110.11111110.11111110=254.254.254.254
2.子网掩码
用来划分网络区域,子网掩码并非0的位数对应ip上的数字表示这个ip的网络位,子网掩码0位对应的数字是ip的主机位。网络位表示网络区域,主机位表示网络区域里某台主机
3.ip通信判定
网络位一致,主机位不一致的2个IP可以直接通讯
172.25.254.1/24 24=225.225.225.0
172.25.254.2/24
12.25…0.1/16
如上三个ip,只有前两个可以直接通讯
4.网络设定工具
ping | 检测网络是否通畅 |
---|---|
ping -c 1 | ping 1 次 |
ping -w 1 | 等待1秒 |
ping -c1 -w1 ip | ping 1 次等待1秒 |
ifconfig | 查看或设定网络接口 |
ifconfig | 查看 |
ifconfig device ip/24 | 设定 |
ifconfig device down | 关闭 |
ifconfig device up | 开启 |
ip addr | 检测或者网络接口 |
ip addr show | 检测 |
ip addr add ip/24 dev device | 设定 |
ip addr del dev ens160 ip/24 | 删除 |
更改ip步骤:
ip addr fiush ens160
|ip addr add dev ens160 172.25.254.11/24
注意:device的名字是一个物理事实,看到什么名字只能用什么名字。
下图配置为暂时性的,重新启动则会失效:
5.图形方式设定ip
设定:
【1】nm-connection-editor
更改:
不建议用服务控制网络
sysermctl restart NetwokManger
建议使用:
nmcli connection show
nmcli connection down wstos
nmcli connection up westos
【2】nmtui
设定:
更改:
无图形模式设置方法:
退出图形模式:
按下Ctrl+Alt+F3
输入用户名、密码:
退出图形模式:
6.命令方式设定网络
nmcli | NetworkManager必须开启 |
---|---|
nmcli device connect ens160 | 启用ens160网卡 |
nmcli devic disconnection ends160 | 关闭ens160网卡 |
nmli device show ens160 | 查看网卡信息 |
nmcli device status ens160 | 查看网卡服务接口信息 |
nmcli connection show | 查看连接 |
nmcli connection down westos | 关闭连接 |
nmcli connection up westos | 开启连接 |
nmcli connection delete westos | 删除连接 |
- 添加连接:
nmcli connection add type ethernet con-name westos ifname ens160 ip4 172.25.254.10/24 - 更改:
nmcli connection modify westos ipv4.addresses 172.25.254.1 00/24
删除连接:
添加连接:
更改连接:
7.管理网络配置文件
网络配置目录
/etc/sysconfig/network-scripts/
网络配置文件的命名规则
ifcfg-xxxx
DEVICE=XXX 设备名称
BOOTPROTO=dhcp|static|none 设备工作方式
ONBOOT=yes 网络服务开启时自动激活网卡
IPADDR= IP地址
PREFIX= 子网掩码
NETMASK=255.255.255.0 子网掩码
NAME= 接口名称
dhcp网络设定
vim /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE=ens160
ONBOOT=yes
BOOTPROTO=dncp
systemctl restart network
实例:
静态网络设置文件
vim /etc/sysconfig/network-scrips/ifcfg-ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=172.25.254.100
NETMASK=255.255.255.0
NAME=westos
systemctl restart<C-F9>network
一块网卡能支配多个IP
vim /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=172.25.254.100
NETMASK=255.255.255.0
BOOPPROTO=none
NAME=westos
IPADDR1=172.25.0.100
PREFIX1=24
systemctl restart network
ip addr show ens160
更改名称:
更改IP:
添加多个IP:
8.lo回环接口
回环接口-----人的神经----127.0.0.1----localhost
9.网关
【1】把westos_node1双网卡主机变成路由器
systemctl start firewalld
firewall-cmd --list
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload
firewall-cmd --list-all
public (defaualt,active)
interfaces: br0 enp0s25 wlp3s0
sources:
services: dhcpv6-client ssh
ports:
masquerade: yes <<< 地址伪装功能开启,真实主机变成路由器
forward-ports:
icmp-blocks:
rich rules:
【2】设定单网卡主机westos_linux的网关
vim /etc/sysconfig/network 全局网关,针对所有没有设定网关的网卡生效
GATEWAY=172.25.254.20
vim /etc.sysconfig/network-scripts/ifcfg-ens160
GATEWAY0=172.25.254.20 档网卡中设定的IP有多个时,指定对于那个IP有效
GATEWAY=172.252.254.20 档网卡中设定的IP只有一个时
route -n 查看网关
Destination Gateway Genmask Flage Metric Ref
Use Iface
10.设定dns
地址解析
系统操作者对字符敏感,系统网络通信需要通过ip地址这个数字,当才做者输入网址www.baidu.com,这个网址不是一个可以通信的IP地址,于是必须要在系统中吧www.baidu.com变成百度服务器的IP地址,这样的过程叫做地址解析
domain name server == 域名解析服务解析就是把域名变成IP
vim /etc/hosts 本地解析文件,此文件中直接提供地址解析ip 域名
220.181.111.188 www.baidu.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时,系统会自动获得ip网关dns,那么/etc/resolv.conf会被或得到的信息修改,如果不需要获得dns信息,在网卡配置文件中加入PREEDNS=no
11.设定解析的优先级
系统默认: /etc/resolv.conf
vim /etc/nsswitch.conf
39 hosts: files dns /etc/hosts优先
vim /etc/nsswich.conf
39 hosts: dns files /etc/resolv.conf dns指向优先
12.dncp服务
在主机中使用镜像找到dhcp-server的安装包
rpm -ivh dhcp-server
cp /usr/share/doc/dhcpd.conf.example /etc/dhcp/dhcpd.conf 用模板生成配置文件
vim /etc/dhcp/dhcpd.conf
# dhcpd. conf
# #
# Sample configuration file for ISC dhcpd
#
# option definitions conmmon 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 als
#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
subnet172.25.254.0netmask255.255.255.0{ 子网设定
range172.25.254.110 172.25.254.200; ip地址
option routers 172.25.254 250: 网关
}
35行之后全部删除
systemctl restart dhcpd
systemctl stop firewall
在络工作模式是dhcp的主机中重后络可以看到
ip
GW
dns
全部获得成功