###1.什么是IP ADDRESS internet protocol ADDRESS??? ##网络进程地址
??ipv4???? internet protocol version 4
1.2x32 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=255.255.255.0 172.25.254.2/24 172.25.0.1/16
####4.网络设定工具 ping?????????????????????????????????? ##检测网络是否通畅 ping -c 1? ????????????????????????? ##ping 1 次 ping -w 1????????????????????????? ##等待1秒 ping -c1 -w1 ip????????????????##ping1次等待1秒
[root@westos_student70 ~]# ping www.baidu.com ##检查网络是否通畅
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=53 time=65.1 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=53 time=69.2 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=53 time=55.3 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=53 time=59.9 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=53 time=65.10 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=53 time=55.10 ms
[root@westos_student70 ~]# ping -c 1 -w 1 www.baidu.com ##等代1秒 ping一次
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=53 time=67.8 ms
--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
ifconfig????????????????##查看或设定网络接口 ifconfig????????????????##查看 ifconfig device ip/24????????????????##设定 ifconfig device down????????????????##关闭 ifconfig device up???????????????????? ##开启
[root@westosa ~]# ifconfig ##查看网卡
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.170 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::298d:9b66:9390:8bc prefixlen 64 scopeid 0x20<link>
ether 52:54:00:06:67:19 txqueuelen 1000 (Ethernet)
RX packets 1193 bytes 193347 (188.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 165 bytes 23844 (23.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 424 bytes 34672 (33.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 424 bytes 34672 (33.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@westosa ~]# ifconfig ens3 down ##关闭网卡
[root@westosa ~]# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 424 bytes 34672 (33.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 424 bytes 34672 (33.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@westosa ~]# ifconfig ens3 up ##开启网卡
[root@westosa ~]# ifconfig
inet 172.25.254.170 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::298d:9b66:9390:8bc prefixlen 64 scopeid 0x20<link>
ether 52:54:00:06:67:19 txqueuelen 1000 (Ethernet)
RX packets 1193 bytes 193347 (188.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 165 bytes 23844 (23.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 424 bytes 34672 (33.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 424 bytes 34672 (33.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ip addr?? ##检测或这顶网络接口 ip addr? show??? ##检测 ip addr? add ip/24 dev device??? ##设定 ip addr? del dev ens160 ip/24? ##删除
[root@westosa ~]# ip addr add 172.25.254.175/24 dev ens3 ##建立新的ip
[root@westosa ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:06:67:19 brd ff:ff:ff:ff:ff:ff
inet 172.25.254.170/24 brd 172.25.254.255 scope global noprefixroute ens3
valid_lft forever preferred_lft forever
inet 172.25.254.175/24 scope global secondary ens3
valid_lft forever preferred_lft forever
inet6 fe80::298d:9b66:9390:8bc/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@westosa ~]# ip addr delete 172.25.245.175/24 dev ens3 ##删除ip
RTNETLINK answers: Cannot assign requested address
[root@westosa ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:06:67:19 brd ff:ff:ff:ff:ff:ff
inet 172.25.254.170/24 brd 172.25.254.255 scope global noprefixroute ens3
valid_lft forever preferred_lft forever
inet6 fe80::298d:9b66:9390:8bc/64 scope link noprefixroute
valid_lft forever preferred_lft forever
####5.图形方式设定ip
设定: 1.nm-connection-editor
#添加连接 nmcli connection add type ethernet con-name westos ifname ens160 ? ip4 172.25.254.100/24
#更改 nmcli connection modify westos? ipv4.addresses 172.25.254.200/24
更改: 不建议用服务控制网络 systemctl restart NetworkManager
建议使用: nmcli connection show nmcli connection down westos nmcli connection up westos
2.nmtui ####6.命令方式设定网络 nmcli????????????????##NetworkManager必须开启
nmcli????????connection????????show????????????????##查看连接 nmcli????????connection????????down ens3 ????? ##关闭连接 nmcli????????connection????????up ens3 ????????????? ##开启连接 nmcli????????connection????????delete ens3 ?????? ##删除连接
[root@westosa ~]# nmcli connection show ##查看
NAME UUID TYPE DEVICE
ens3 45deaabe-f323-4b25-bade-9ccf0a24a776 ethernet ens3
[root@westosa ~]# nmcli connection down ens3 ##关闭
[root@westosa ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens3 45deaabe-f323-4b25-bade-9ccf0a24a776 ethernet --
[root@westosa ~]# nmcli connection up ens3 ##开启
[root@westosa ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens3 45deaabe-f323-4b25-bade-9ccf0a24a776 ethernet ens3
####8.lo回环接口 回环接口------人的神经----127.0.0.1-----localhost
####9.网关#####
vim /etc/sysconfig/network????????????????##全局网关,针对所有没有设定网关的网卡生效 GATEWAY=172.25.254.250
vim /etc/sysconfig/network-scripts/ifcfg-ens160????????????????##档网卡中设定的IP有多个时,指定对于那个IP生效 GATEWAY0=172.25.254.20
GATEWAY=172.25.254.20????????????????##档网卡中设定的IP只有一个时
route -n???? ##查看网关????????
Destination????????????????Gateway????????????????Genmask????????????????Flags??? Metric????????Ref??????????UseIface?????? 0.0.0.0??????? ? ? ? ? ? ? ? ? ? 172.20.10.2? ? ? ? ? 0.0.0.0?????? ? ? ? ? ? ? ? ? UG??? 100?? ? ? ? ? ?? 0??????? 0 ens3 1.1.1.0?????? ? ? ? ? ? ? ? ? ? ? ?? 0.0.0.0???????? 255.255.255.0? ? ? ? ? ? ? ? ? U???? 100?? ? ? ? ? ?? 0??????? 0 ens3 172.20.10.2??????????????????? 0 .0.0.0???????? 255.255.255.255 ? ? ? ? ?? UH??? 100 ? ? ? ? ?? ? 0??????? 0 ens3 172.25.254.0?????????????????? 0.0.0.0???????? 255.255.255.0 ? ? ? ? ? ? ? ?? U???? 100?? ? ? ? ? ?? 0??????? 0 ens3
cd /etc/sysconfig/network-scripts
ls
ifcfg-westos
vim ifcfg-westos
[root@westosa network-scripts]# cat ifcfg-westos
DEVICE=ens3
ONBOOT=yes
BOOTPROTO=none
IPADDR0=172.25.254.170
NETMASK0=255.255.255.0
IPADDR1=1.1.1.170
PREFIX1=24
NAME=westos
GATEWAY0=172.20.10.2
[root@westosa ~]# vim /etc/sysconfig/network
[root@westosa ~]# cat /etc/sysconfig/network
# Created by anaconda
# GATEWAY=172.20.10.2
firewall-cmd --add-masquerade 配置防火墙 添加地址伪装
nmcli connection reload
nmcli connection up westos
##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;?????????
##dnsdefault-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
测试: 在网络工作模式是dhcp的主机中重启网络 可以看到 ip GW dns 全部获取成功
|