1.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位为主机位
2.配置ip
<<图形化>>
1.图形界面
nm-connection-editor
2.文本化图形
nmtui
<<命令>>
ifconfig 网卡 ip netmask ##临时设定
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes #添加dhcp网络
nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24 #添加静态网络
nmcli connection delete westos #删除westos链接
nmcli connection show #显示所有网络链接
nmcli connection down westos #关闭指定链接
nmcli connection up westos #开启指定链接
nmcli connection modify “westos” ipv4.addresses newip/24 #改变wetos的ip
nmcli connection modify “westos” ipv4.method
3.gateway 网关
1.路由器
主要功能是用来作nat的
dnat 目的地地址转换
snat 源地址转换
2.网关
路由器上和自己处在同一个网段的那个ip
3.设定网关
systemctl stop NetwrokManager
vim /etc/sysconfig/network ##全局网关
GATEWAY=网关ip
vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件 ##网卡接口网关
GATEWAY=网关ip
systemctl restart netwrok
route -n ##查询网关
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 (网关)172.25.0.254 0.0.0.0 UG 0 0 0 eth0
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
5.dns
1.dns
dns是一台服务器
这太服务器提供了回答客户主机名和ip对应关系的功能
2.设定dns
vim /etc/resolv.conf
nameserver dns服务器ip
vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件
DNS1=dns服务器ip
3.本地解析文件
vim /etc/hosts
ip 主机名称
4.本地解析文件和dns读取的优先级调整
/etc/nsswitch.conf
38 #hosts: db files nisplus nis dns
39 hosts: files dns ##files代表本地解析文件,dns代表dns服务器,那个在前面那个优先
5.dhcp服务的配置
[root@server0 ~]# yum install -y dhcp
安装dhcp软件包
[root@server0 dhcp]# cat /etc/dhcp/dhcpd.conf
DHCP Server Configuration file.
see /usr/share/doc/dhcp*/dhcpd.conf.example
see dhcpd.conf(5) man page
查看dhcpd服务配置文件
[root@server0 dhcp]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
拷贝配置文件
编辑配置文件
[root@server0 dhcp]# vim /etc/dhcp/dhcpd.conf
7 option domain-name “westos.com”;
8 option domain-name-servers 172.25.254.100;
27 #subnet 10.152.187.0 netmask 255.255.255.0 {
28 #}
32 subnet 172.25.254.0 netmask 255.255.255.0 {
33 range 172.25.254.110 172.25.254.120;
34 option routers 172.25.254.100;
35 }
35行之后全部删除
[root@server0 dhcp]# systemctl start dhcpd
[root@server0 dhcp]# systemctl status dhcpd
dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled)
Active: active (running) since Thu 2017-11-02 11:34:44 CST; 3s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 3024 (dhcpd)
虚拟机上网
可以连接网络的主机添加火墙策略
firewall-cmd –permanent –add-masquerade
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=172.20.10.2 masquerade’
规则内添加的地址是我们可以连接网络获取到的ip地址
wlp3s0:inet 172.20.10.2
firewall-cmd –reload
虚拟机
vim /etc/resolv.conf
nameserver 172.20.10.1 真机连接网络获取到的dns
vim /etc/sysconfig/network
GATEWAY=172.25.254.250 通过哪台主机去连接网络