一、IP网址
计算机要实现网络通信,就必须要有一个用于快速定位的网络地址
IP就是计算机在网络中的唯一ID
IP地址=网络地址+主机地址
二、子网掩码
用来划分网络区域
子网掩码非0位置对应的ip上的数字表示这个ip的网络位子网掩码0位对应的数字是ip的主机位
三、网络设定工具
临时设定
ping检测网络是否畅通
ifconfig查看或设定网络接口
ifconfig查看
ifconfig device(etho网卡名称)ip/24#设定
ifconfig device dow关闭
ifconfig device up启
ip addr检测或设定网络接口
ip addr show检测
ip addr add ip/24 dev device(etho网卡名称)#设定
注意:device名字是一个物理事实,你看到的是什么名字用什么名字
四、图形方式设定IP
nm-connection- editor ##nm- networkManager
有可能不生效
systemctl stop NetworkManager记录网络服务状态
systenctt restart network
命令的方式设定网络
nmcli device disconnect etho#关闭etho网络
nmcli device connect etho#开启etho网卡
nmcli device show etho#查看网卡信息
nmcli device status etho查看网卡服务接口信息 nmcil connection show
nmcli connection down westos
nmcli connection up westos
nmcli connection delete westos
nmcli connection add type ethernet con-name redhat ifname etho ipv4172.25.254.100/24
nmcli connection modify redhat ipv4.addresses 172.25.254.200/24
nmcli connection down westos nmcli connection up westos
nmcli connection modify redhat ipv4.method auto网卡的工作方式为动态 nmcli connection modify redhat ipv4.method manual#网卡的工作方式为静态
五、管理网络配置立件
网络配位置目录
/etc/sysconfig/network-scripts/
HWADDR=52:54:00:00:00#mac地址
Type=Ethernet网络类型
BOOTPROTO=none| static |dhcp网络设备的工作模式
IPADDRO=172.25.254.200 IP地址
PREFIXO=24子网掩码
NAME=westos网络名称
UUID=65d4b13e-64c7-41cd-944e-ee4d862ba734
ONBOOT=yes网络设备开启时自动激活网卡
示例
静态网络设定文件
vim /etc/sysconfig/network-scripts/ifcfg-redhat
DEVICE=eth0
ONBOOT=yes
IPADDR=172.25.254.200
NETMASK=255.255.255.0
BOOTPROTO=statoc
NAME=westos
systemctl restart network
六、虚拟机上网--------网关
把真实主机变成路由器---------------------(路由器上配置的ip就是网关)
systemctl start firewallId
firewall-cmd–list-all
trusted( active)
target:ACCEPT
icmp- block- inversion: no
interfaces: br0 enp0s25 wlp3s0
sources:
services:
ports
protocols
masquerade:no地址伪装功能
forward- ports
sourceports
icmp blocks:
rich rule:
firewall- cmd-- permanent --add- masquerade
firewalL-cmd --reload
firewall-cmd–list-all
firewall-cmd–list-all
trusted (active)
target: ACCEPT
icmp-block-inversion: no
interfaces: bro enp0s25 wlp3s0
sources:
services:
ports
protocols:
masquerade:yes 地址伪装功能开启,真实主机变成路由器
forward- ports:
sourceports:
icmp- blocks
rich rules
给虚拟机设定网关
vim/etc/sysconfig/network全局网关,针对所有没有设定同关的网卡上的网络生效
GATEWAY=172.25.254.250(真机IP)
vim /etc/sysconfig/network- scripts/ifcfg-name
GATEWAY0=172.25.254.250
GATEWAY1=172.25.254.250
GATEWAY=172.25.254.250#网卡中只有一个IP地址的时候
systemctl restart network
route -n# 查看网关
设定DNS
#DNS=domain name server
vim/etc/ resolv.conf#DNS的指向文件nameserver114.114.114.114#当需要某个域名的IP地址的时候去问114.114.114114
vim /etc/sysconfig/network-scripts/ifcfg-name
DNS=144.144.144.144
vim /etc/hosts 本地解析文件
ip 域名
系统默认
/etc/hosts > /etc/resolv.conf
vim /etc/nsswitch.conf
39hosts: dns file /etc/resolv.conf执向优先
39hosts: file dns /etc/hosts 优先
dhcp服务配置
vim /etc/hosts
172.25.254.250content.example.com
yum install dhcp-y
cp /usr/share/doc/dhcp-4.2.5/dhcpd. conf. example /etc/dhcp/dhcpd. conf
option domain- name " example. com":域名
8 option domain- name- servers 114 114 114 114: #DNS
27删除
28删除
30 subnet172.25.254.0 netmask255.255.255.0{#子网设定
31 range172.25.254.100 172.25.254.130;#IP池(IP范围
32 option routers172.25.254.19;#网关
33
以下内容全部删除
systemctl start dhcpd
两台虚拟机: systemctl stop firewall
七、dhcp服务(动态IP管理)
vim /etc/hosts
172.25.254.250 content.example.com
yum install dhcp -y
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
7 option domane-name"ezample.com"; ##域名
8 option domane-name-servers 144.144.144.144: ##DNS
删除27 28 行
30 subnet 172.25.254.0(网段) netmask 255.255.255.0(子网掩码){
31 range 172.25.254.100 172.25.254.130: ip池 (ip范围)
32 option routers 172.25.254.49; (网关)
33 }
删除34行之后的内容
systemctl start dhcpd
两台虚拟机关闭防火墙