Linux ~ 计算机网络。

2015 年。发展方向 -> python 、 hadoop。
Linux 高端运维工程师课程。
www.itxdl.cn/linux



part 1 ~ Linux 网络设置与远程管理。

网络基础知识、Linux 中常用的网络命令、Linux 中 ip 地址的配置方式、SSH 远程连接管理、VNC 远程管理等内容。为部分主要是基础知识,让大家对 Linux 网络服务有个初步认识。

part 2 ~ Linux 文件服务器。

主要讲解 Linux 中最主要的文件共享服务 FTP 服务、Samba 服务和 NFS 服务等内容。这些是在工作中非常常见的文件服务器,我们办公环境中经常需要进行文件和资料共享。

part 3 ~ 常见的 Linux 服务。

主要讲解 DHCP(动态主机配置协议)服务、DNS(域名系统)服务等内容。这些是我们常见的 Linux 服务,主要用来让 Linux 可以进行 IP 地址自动分配和进行域名解析。

Part 4 ~ Web 开发环境搭建与维护。

主要讲解 LAMP 环境搭建、LNMP 环境搭建、Apache 服务器配置、Nginx 服务器配置等内容。Web 服务是目前最常用的 Linux 服务器,我们会学习如何搭建一个完整的 LAMP 和 LNMP 开发环境,并学习 Apache 服务器与 Nginx 服务器的常用功能与配置。

计算机基础。

进制转换。

十进制。-> 0~9 表示。
十进制 -> 二进制。(decimal % 2)-> 余数倒取。
二进制 -> 十进制。(binary 的各位(基数)× 2 ^ n)。

装水桶法。(适用于(小的数))一般用于网络地址。
eg. 137(decimal)->(binary)。
1 1 1 1 1 1 1 1
128 64 32 16 8 4 2 1

用 137 - (可以减去的)最大数(从 128 开始)。
137 - 128 = 9,大于 0 。 -> 这一位取 1。
依次。-> 9 - 64 < 0。 -> 这一位取 0。
9 - 32 < 0。 -> 这一位取 0。
9 - 16 < 0。 -> 这一位取 0。
9 - 8 = 1 大于 0。 -> 这一位取 1。
1 - 4 < 0。 -> 这一位取 0。
1 - 2 < 0。 -> 这一位取 0。
1 - 1 = 0。 -> 这一位取 1。

=》 最终结果:137(decimal) = 10001001(binary)。

二进制 -> 十进制。eg. 110110
1 1 1 1 1 1 1 1
128 64 32 16 8 4 2 1

0 0 1 1 0 1 1 0

32 + 16 + 4 + 2 = 54。

hexadecimal —> decimal。

先转为二进制。
8ea
8 e(14) a(10)
1000 1110 1010
再转为十进制。
2 + 8 + 32 + 64 + 128 + 2048 = 2282。

decimal —> hexadecimal。

先转换为二进制。
297 —> 100101001。
再转为十六进制。
0001 0010 1001
1 2 9




网络基础。

互联网概述。
互联网接入方式。


2.1. 互联网概述。

Internet 简介。

  • Internet 是国际互联网。就像洲际公路系统将各个城市链接在一起一样,Internet 同样也连接着成千上万的计算机网络。
  • Internet 计算机网络还是一个巨大的信息海洋,涉及书籍、教育、电影、时事、运动、艺术、文化、技术开发等内容。

互联网。1960s。
ARPAnet —> 美国军方为了战争开发。 —> TCP / IP。
+美国基金会开发了 NSFnet。
IBM 领衔三家巨头公司开发 ANSnet。
所有汇总产生 —>
Internet。

Internet 的作用。

  • 互联网缩短了时空的距离,大大加快了信息的传递,使得社会的各种资源得以共享。
  • 互联网创造出了更多的机会,可以有效地提高传统产业的生产效率,有力地拉动消费需求,从而促进经济增长。
  • 互联网为各个层次的文化交流提供了良好的平台。

Internet 应用领域。
典型应用。

www。万维网。
FTP。文件传输协议。
E-MAIL。电子邮件。

www(World Wide Web)。又称全球网、环球网或万维网等,也可以简称为 Web。
典型的 Client / Server 架构。



统一资源定位。

协议 + 域名 或 IP:端口 + 网页路径 + 网页名
http://www.lampbrother.net:80/index.html

.net —> 一级域名。
lampbrother —> 二级域名。全球唯一。(区分钓鱼网站)。
www —> 三级域名。

浏览器默认协议:http。
http 协议默认端口:80。
设置默认文件名:index.html。

常见一级域名。

  • 组织一级域名。
    .edu 教育机构
    .com 商业组织
    .gov 非军事政府机构
    .mil 军事机构
    .org 其他组织
    .net 网络服务机构
  • 地区一级域名。—> 域名分配组织规定。
    au, cn, in, us, uk


2.2. 互联网接入方式。

  • ADSL:非对称数字用户环路。

ADSL 可以提供最高 1Mbps 的上行速率和最高 8Mbps 的下行速率。最新的 ADSL2+ 技术可以提供最高 24Mbps 的下行速率。ADSL2+ 技术打破了 ADSL 接入方式带宽限制有瓶颈,使其应用范围更加广阔。

Mbps = Mbit / s。
1024 Kbps = 1024 / 8 KByte / s = 128 KB / s。

  • 优点。

使用电话线,节省了布网成本。
上网的同时可以打电话,节省了电话费。

  • 缺点。

铜线耗材昂贵。
带宽限制。
动态 IP 地址。
断网后 IP 会被回收,可以循环使用。24 小时强制更换。
域名通过 DNS 转化为 IP。—> 服务器不能稳定使用。

使用:PPPoE。
TP-LINK 拨号。

  • FTTH。

光纤入户的带宽更高,而光纤的员材料是二氧化硅,在自然界取之不尽用之不竭。当然也是动态 IP 地址。
光纤路由器、交换机价格昂贵。

  • 小区宽带。

小区宽带是一个大局域网,所有客户都在同一个网段中。外网接口可以是 FTTH,也可以是固定 IP 的光纤。
共享带宽。
监听网关可以抓取信息。

  • 固定 IP 光纤。

带宽自由申请,价格最贵。因为固定 IP 地址,所以可以搭建服务器。
4 个 IP:
IP 地址。
网络地址。
广播地址。
网关。



1.5. OSI 七层模型和 TCP 四层模型。

  • 网络通信协议。
    • OSI 七层模型和 TCP 四层模型。
      网络层协议和 IP 划分。
    • OSI 七层架构。
      网络模型混乱,ISO 组织提出 OSI 网络模型标准。

在这里插入图片描述
上 3 层。给用户提供服务。
上 6 层(横线联系)是逻辑联系。
物理层实际传递消息。物理联系。

发送。
由上到下。
接收。
由下到上。

处理复杂问题:分责任。—> 分治法。

  • 应用层。
    // APDU。Application Protocol Data Unit。应用协议数据单元。

用户接口。

  • 表示层。
    // PPDU。Presentation Protocol Data Unit。表示协议数据单元。

数据的表现形式(编码、文件形式…)、特定功能的实现,eg. 压缩、加密。

  • 会话层。
    // SPDU。Session Protocol Data Unit。会话协议数据单元。

对应用会话的管理、同步。

— 以上没有实际的数据传递。 —

  • 传输层。·「传输层包头」。
    // TPDU。Transport Protocol Data Unit。传送协议数据单元。

可靠与不可靠的传输(定义 TCP or UDP)、传输前错误检测(TCP 支持差错校验)、流控。

mac 地址负责局域网通信。
ip 地址负责外网通信。

TCP 协议(Transmission Control Protocol),传输控制协议。面向连接的、可靠的、基于字节流的传输层通信协议。
UDP 协议(User Datagram Protocol),用户数据报协议。面向无连接的不可靠协议。
  • 网络层。·「传输层包头」·「网络层包头」
    // 报文。

提供逻辑选址、路由选择。ip 地址。

  • 数据链路层。·「传输层包头」·「网络层包头」·「数据链路层包头」
    // 帧。

组帧、用 MAC 地址访问媒介、错误检测与修正。

mac 地址。固化在 ROM 存储器中。48 位,十六进制。mac 和交换机之间沟通在数据链路层。在数据链路层写入 MAC 地址。
  • 物理层。·「传输层包头」·「网络层包头」·「数据链路层包头」+ 原始数据发送出。
    // 比特。

设备之间的比特流的传输、物理接口、电气特性等。

在这里插入图片描述
主机 B。
各层次查看包含自己包头的信息。(邮件分拣)。
数据链路层。—> 看是不是自己的信息,如果不是直接扔了。



TCP / IP 协议 4 层模型。
  • 应用层。
  • 传输层。
  • 网际互联层。
  • 网络接口层。

在这里插入图片描述
TCP / IP 模型 1970s。
OSI 模型 1980s。(参考、标准)。

  • 网络接口层。
网络接入层与 OSI 参考模型中的 物理层数据链路层相对应。ta 负责监视数据在主机和网络之间的交换。事实上,TCP / IP 本身并未定义该层的协议,而由参与互连的各网络使用自己的物理层和数据链路层协议,然后与 TCP / IP 的网络接入层进行连接。 地址解析协议(ARP)工作在此,即 OSI 参考模型的数据链路层。
~ ~
ARP:IP —> MAC。
RARP:MAC —> IP。反向地址解析协议。
arp -a
C:\Users\geek>arp -a

接口: 192.168.0.104 --- 0x4
  Internet 地址         物理地址              类型
  192.168.0.1           80-89-17-83-9c-64     动态
  192.168.0.106         ac-7b-a1-62-66-c8     动态
  192.168.0.255         ff-ff-ff-ff-ff-ff     静态
  224.0.0.22            01-00-5e-00-00-16     静态
  224.0.0.251           01-00-5e-00-00-fb     静态
  224.0.0.252           01-00-5e-00-00-fc     静态
  239.255.255.250       01-00-5e-7f-ff-fa     静态
  255.255.255.255       ff-ff-ff-ff-ff-ff     静态

接口: 192.168.85.1 --- 0xb
  Internet 地址         物理地址              类型
  192.168.85.254        00-50-56-f6-20-8d     动态
  192.168.85.255        ff-ff-ff-ff-ff-ff     静态
  224.0.0.22            01-00-5e-00-00-16     静态
  224.0.0.251           01-00-5e-00-00-fb     静态
  224.0.0.252           01-00-5e-00-00-fc     静态
  239.255.255.250       01-00-5e-7f-ff-fa     静态
  255.255.255.255       ff-ff-ff-ff-ff-ff     静态

接口: 192.168.142.1 --- 0x11
  Internet 地址         物理地址              类型
  192.168.142.254       00-50-56-f3-4b-75     动态
  192.168.142.255       ff-ff-ff-ff-ff-ff     静态
  224.0.0.22            01-00-5e-00-00-16     静态
  224.0.0.251           01-00-5e-00-00-fb     静态
  224.0.0.252           01-00-5e-00-00-fc     静态
  239.255.255.250       01-00-5e-7f-ff-fa     静态
  255.255.255.255       ff-ff-ff-ff-ff-ff     静态
  • 网际互联层。

网际互联层对应于 OSI 参考模型的网络层,主要解决主机到主机的通信问题。ta 所包含的协议设计数据包在整个网络上的逻辑传输。该层有三个主要协议:网际协议(IP)、互联网组管理协议(IGMP)和互联网控制报文协议(ICMP)。

  • 传输层。

传输层对应于 OSI 参考模型的传输层,为应用层实体提供端到端的通信功能,保证了数据包的顺序传送及数据的完整性。该层定义了两个主要的协议:传输控制协议(TCP)和用户数据报协议(UDP)。



TCP / IP 三次握手。

在这里插入图片描述



端口。

在这里插入图片描述
ip 确定哪一台计算机,端口确定哪一个软件。

netstat -an
C:\Users\geek>netstat /h

显示协议统计信息和当前 TCP/IP 网络连接。

NETSTAT [-a] [-b] [-e] [-f] [-n] [-o] [-p proto] [-r] [-s] [-x] [-t] [interval]

  -a            显示所有连接和侦听端口。
  -b            显示在创建每个连接或侦听端口时涉及的
                可执行程序。在某些情况下,已知可执行程序承载
                多个独立的组件,这些情况下,
                显示创建连接或侦听端口时
                涉及的组件序列。在此情况下,可执行程序的
                名称位于底部 [] 中,它调用的组件位于顶部,
                直至达到 TCP/IP。注意,此选项
                可能很耗时,并且在你没有足够
                权限时可能失败。
  -e            显示以太网统计信息。此选项可以与 -s 选项
                结合使用。
  -f            显示外部地址的完全限定
                域名(FQDN)。
  -n            以数字形式显示地址和端口号。
  -o            显示拥有的与每个连接关联的进程 ID。
  -p proto      显示 proto 指定的协议的连接;proto
                可以是下列任何一个: TCP、UDP、TCPv6 或 UDPv6。如果与 -s
                选项一起用来显示每个协议的统计信息,proto 可以是下列任何一个:
                IP、IPv6、ICMP、ICMPv6、TCP、TCPv6、UDP 或 UDPv6。
  -q            显示所有连接、侦听端口和绑定的
                非侦听 TCP 端口。绑定的非侦听端口
                 不一定与活动连接相关联。
  -r            显示路由表。
  -s            显示每个协议的统计信息。默认情况下,
                显示 IP、IPv6、ICMP、ICMPv6、TCP、TCPv6、UDP 和 UDPv6 的统计信息;
                -p 选项可用于指定默认的子网。
  -t            显示当前连接卸载状态。
  -x            显示 NetworkDirect 连接、侦听器和共享
                终结点。
  -y            显示所有连接的 TCP 连接模板。
                无法与其他选项结合使用。
  interval      重新显示选定的统计信息,各个显示间暂停的
                间隔秒数。按 CTRL+C 停止重新显示
                统计信息。如果省略,则 netstat 将打印当前的
                配置信息一次。


C:\Users\geek>

在这里插入图片描述
端口号:应用层传输层之间。
分 TCP 协议端口号和 UDP 协议端口号。65535 个 + 65535 个。(2^16)。

DNS。Domain Name System。:53

主从服务器域名记录更新:TCP。
客户端去服务器查询域名:UDP。—> 快。网页有时候打不开,刷新一下。(UDP 丢包)。



应用层。

应用层对应于 OSI 参考模型的高层,为用户提供所需要的各种服务。
eg FTPTelnetDNSSMTP 等。



数据封装过程。

在这里插入图片描述



TCP / IP 模型与 OSI 模型的比较。
  • 共同点。

OSI 参考模型和 TCP / IP 模型都采用了层次结构的概念。
都能提供面向连接和无连接两种通信服务机制。

  • 不同点。

前者是七层模型,后者是四层结构。
对可靠性要求不同(后者更高)。
OSI 模型是在协议开发前设计的,具有通用性。TCP / IP 是先有协议集然后建立模型,不适用于非 TCP / IP 网络。
实际市场应用不同。OSI 模型只是理论上的模型,并没有成熟的产品,而 TCP / IP 已经成为“实际上的国际标准”。




Linux 的 IP 地址配置。
Linux 网络配置文件。
常用网络命令。1.
常用网络命令。2.
虚拟机网络参数配置。

在这里插入图片描述
在这里插入图片描述
ip v4 长度不定。

在这里插入图片描述
不同网段。

路由器:跨网络通信。

  • a 类。
    1.0.0.0
    2.0.0.0
    (不同网段)。

1.0.0.0 代表网络本身,不能分配。
1.255.255.255 代表当前网络的广播地址。

  • B 类。

前 2 位代表一网段。

  • C 类。

前 3 位代表一网段。

私有 IP 地址范围内,

不需要花钱。不能访问公网。节约有限公网资源。



子网掩码。
  • 255.0.0.0(A 类,前 8 位确定是否是同一网段,后 24 位不同主机)。
  • 255.255.0.0(B 类,前 16 位确定是否是同一网段,后 16 位不同主机)。
  • 255.255.255.0(C 类,前 24 位确定是否是同一网段,后 8 位不同主机)。

和 IP 一起查看。

确定是否是同一网段。

在这里插入图片描述
B 类 ip 和 C 类子网掩码。

使用 C 类子网掩码确定网段。

逻辑相与:网络地址。

广播地址:子网掩码有多少 0 位,将 0 位全变为 1。



端口。

ip:门牌号。

端口:家里的 N 口人,哪一个人。

  • TCP 协议包头。

在这里插入图片描述

  • UDP 协议包头。

在这里插入图片描述



常见端口号。

FTP(文件传输协议)端口号:20 21。

SSH(安全 shell 协议)端口号:22。

telnet(远程登录协议)端口号:23。

DNS(域名系统)端口号:53。

http(超文本传输协议)端口号:80。

SMTP(简单邮件传输协议)端口号:25。

POP3(邮局协议 3 代)端口号:110。



netstat -an(o)


DNS。
  • 在互联网中,通过 IP 地址来进行通信。

  • IP 地址用数字表示,记忆起来太困难了(eg. 116.213.120.232)。

  • 人对域名更加敏感,如:http://www.imooc.com/



hosts。

hosts 解析优先级高于 DNS。

  • 早期 Hosts 文件解析域名。

名称解析效能下降。
主机维护困难。

  • DNS 服务。

层次性。
分布式。

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述



网关。
  • 网关(Gateway),又称网间连接器、协议转换器。

  • 网关在网络层以上实现网络互连,是最复杂的网络互连设备,仅用于两个高层协议不同的网络互连。

  • 网关既可以用于广域网互连,也可以用于局域网互连。

  • 网关是一种充当转换重任的服务器或路由器。

局域网(同网段),使用交换机 + MAC 地址。
交换机接口记录 MAC 地址。

不同网段,使用路由器。

网关:交换机 or 路由器。

内网 —> 网关 —> 公网。

在这里插入图片描述



上公网:网关 + DNS。


Linux 的 IP 地址配置。

Linux 一切皆文件,想要永久生效,就写入文件。

ifconfig 命令临时配置 IP 地址。

interface config

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:46:AF:19  
          inet addr:192.168.223.129  Bcast:192.168.223.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe46:af19/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:97275 errors:0 dropped:0 overruns:0 frame:0
          TX packets:35825 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:140088610 (133.5 MiB)  TX bytes:2419329 (2.3 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

eth0 —> ethernet —> 以太网。(CentOS 6)。
以太网 —> 运行在数据链路层的网络。
lo -> loopback。
每台计算机都有。仅代表网络协议正常。127.0.0.1 —> 本机。

Windows / Linux 允许一块网卡添加多个 IP 地址。IP 共享网络硬件的带宽。

ifconfig eth0:0 192.168.2.251 netmask 255.255.255.0
ifconfig eth0:1 192.168.3.251 netmask 255.255.255.0
# 取消。
ifconfig eth0:1 down
# 启动。
ifconfig eth0:1 up


setup 工具永久配置 IP 地址。

红帽专有图形化工具 setup 设置 IP 地址。
CentS7 —> nmtui。

service network restart



Linux 网络配置文件。
  • 修改网络配置文件。

等号左侧大写,等号右侧小写,等号两侧没有空格。

*** ~ 如果有 DHCP,只需要这几个。

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 

***DEVICE=eth0***		# 网卡设备名。与文件名一致。
***TYPE=Ethernet***	# 以太网。
UUID=2cd425db-fb60-4b65-9bf8-dd2438722fb9	# 唯一识别码。CentOS 6 开始。
***ONBOOT=yes***	# 是否随网络服务启动,eth0 生效。CentOS 6 默认 no。
NM_CONTROLLED=yes	# 是否可以由 Network Manager 图形管理工具托管。
***BOOTPROTO=dhcp***	# 自动获取 IP(none、static、dhcp·」「要求局域网内有 DHCP 服务器」)。
***HWADDR=00:0C:29:46:AF:19***	# MAC 地址。
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
~                                                                                 
~                                                                                 
~                                                                                 
"/etc/sysconfig/network-scripts/ifcfg-eth0" 13L, 231C

如果 BOOTPROTO 为 dhcp, 则文件中只需 5 个加粗(B)和斜体(I)的配置项。(需要局域网内有 DHCP 服务器)。



主机名。
[root@localhost ~]# vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=localhost.localdomain	# Linux 主机名可以相同。
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
"/etc/sysconfig/network" 2L, 46C

[root@localhost ~]# hostname
localhost.localdomain


DNS 配置文件。
[root@localhost ~]# cat /etc/resolv.conf 
; generated by /sbin/dhclient-script
search localdomain		# 域名补全。(如果地址没有输入完整,自动加“.localdomain”)
nameserver 192.168.223.2

search localdomain # 域名补全。(如果地址没有输入完整,自动加“.localdomain”)
eg. www.baidu(回车)—> www.baidu.localdomain。



图形界面配置 IP 地址。


常用网络命令。1.

  • ifconfig —> 查看与配置网络状态命令。(临时)。

看不到网关的 DNS。

  • hostname [主机名] —> 查看或设置主机名命令。
[root@localhost ~]# hostname
localhost.localdomain
  • 关闭或开启网卡。

    • ifdown 网卡设备名
      // 禁用该网卡设备。
    • ifup 网卡设备名
      // 启用该网卡设备。
  • 查询网络状态。

netstat [选项]
选项:
-t。 列出 TCP 协议端口。
-u。 列出 UDP 协议端口。
-n。 不使用域名与服务名,而使用 IP 地址和端口号。
-l。 仅列出在监听状态网络服务。
-a。 列出所有的网络连接。

netstat -tlun  # 不能看到已经连接的端口。
netstat -an  # 查看正在连接的端口。State -> LISTEN + ESTABLISHED(连接已经存在)连接没有正确退出。连接数限制 256 个。
netstat -an | grep ESTABLISHED | wc -l # 统计。
netstat -rn  # -r 列出路由列表,功能和 route 命令一致。
route -n  # 查看路由列表(最后一个 gateway 是网关)。

网关:邮局。

临时设置网关。

route add default gw 192.168.0.2
route del default gw 192.168.0.2

在这里插入图片描述

  • 域名解析命令。

nslookup [主机名或 IP]
// 进行域名与 IP 地址解析。

-bash: nslookup: command not found
[root@localhost ~]# yum install -y bind-utils
[root@localhost ~]# nslookup
> server
Default server: 192.168.223.2
Address: 192.168.223.2#53
// 查看本机 DNS 服务器。
[root@localhost ~]# nslookup www.baidu.com
Server:		192.168.223.2
Address:	192.168.223.2#53

Non-authoritative answer:
Name:	www.baidu.com
Address: 182.61.200.7


常用网络命令。2.

  • ping 命令。

ping [选项] ip 或域名
// 探测指定 IP 或域名的网络状态。
选项:-c 次数。指定 ping 包的次数。

  • telnet 命令。# 明文传递数据包。不推荐使用。推荐使用 ssh。

telnet [域名或 IP] [端口]
// 远程管理与端口探测命令。

使用:查看别人计算机端口是否开启。本机用 netstat -tlun
最好不要在服务器开启 22 端口。最好不要安装 telnet-server。

可以用来测试对方开了哪些端口。

telnet 192.168.142.168 80

  • traceroute 命令。

traceroute [选项] IP 或域名
// 路由跟踪命令。
选项。
-n。—> 使用 IP,不使用域名,速度更快。

查看经过了哪几个路由器。

[root@localhost ~]# traceroute 192.168.0.103
traceroute to 192.168.0.103 (192.168.0.103), 30 hops max, 60 byte packets
 1  192.168.223.2 (192.168.223.2)  0.175 ms  0.084 ms  0.089 ms
 2  192.168.0.103 (192.168.0.103)  0.274 ms  0.331 ms  0.153 ms

出现了 * 号:节点禁止 ping。

Windows 中命令是:tracert。

  • wget 命令。
    // 下载命令。


抓包。

tcpdump -i eth0 -nnX port 21

ftp / telnet 明文。



虚拟机网络配置。

Linux 的 IP 地址配置。
  • 修改并配置 IP 地址。
[root@localhost ~]# setup

# 或以上各种方法(配置文件)。
  • 启动网卡。

ONBOOT=yes。

拨号网络是动态 IP。

  • 重启网络服务。
[root@localhost ~]# service network restart
  • 设置虚拟机网络连接方式。

    • Bridged ( connect VMs directly to the external network ) 。

      桥接:直接连接到物理网络。(check: 复制物理网络连接状态)(B)。
      独占一个 IP 地址。
      (使用“本地连接”网卡,使用真实网卡和主机通讯)。
      需要选择桥接到哪一块网卡(有线 or 无线 or 自动)。

    • NAT ( share host’s P addess with VMs ) 。

      NAT:使用已共享的主机 IP 地址(N)。
      使用 VMnet 8 网卡和主机通讯。
      如果真实主机能上网,Virtual Machine 也可以。
      但不能和局域网内其他主机通讯。
      192.168.25.* —> 同一网段。

    • Host-only ( connect VMs internally in a private network ) 。

      Host-only:与主机共享一个私有网络(H)。
      使用 VMnet 1 网卡。
      只能和真实主机联网通讯。

  • 克隆虚拟机。

    • 链接克隆。
    • 原始克隆。
    • 需要修改 UUID。
    [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
    # 删除 MAC 地址行。
    [root@localhost ~]# rm -rf /etc/udev/rules.d/70-persistent-net.rules 
    # 删除网卡和 MAC 地址绑定文件。
    
    重启系统。—> 自动计算一个 UUID。
    


SSH 远程管理服务。

SSH 简介。
SSH 原理。
SSH 配置文件。
常用 SSH 命令。
SSH 连接工具。
私钥对登陆。

ssh。

SSH 为 Secure Shell 的缩写,安全外壳协议。SSH 为建立在应用和传输层基础上的安全协议。

SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在应用层基础上的安全协议。SSH 是较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。SSH 最初是 UNIX 系统上的一个程序,后来又迅速扩展到其他操作平台。SSH 在正确使用时可弥补网络中的漏洞。SSH 客户端适用于多种平台。几乎所有 UNIX 平台—包括 HP-UX、Linux、AIX、Solaris、Digital UNIX、Irix,以及其他平台,都可运行 SSH。

telnet 远程时明文传递。

SSH 远程时加密数据。

vsftpd —> ftp 服务器端。

  • ftp —> 21 端口。
[root@localhost ~]# service vsftpd restart
Shutting down vsftpd:                                      [FAILED]
Starting vsftpd for vsftpd:                                [  OK  ]
  • tcpdump —> Linux 字符界面抓包。
[root@localhost ~]# tcpdump -i eth0 -nnX port 21
# -i。 —> 指定监听 eth0 网卡。
# -nn。 —> 用 IP 地址形式监听。
# -X。 —> 数据包是十六进制的。用十六进制分析数据包。
# port 21。 —> 指定监听端口。

The virtual machine’s operating system has attempted to enable promiscuous mode on adapter ‘Ethernet0’. This is not allowed for security reasons.
Please go to the Web page “http://vmware.com/info?id=161” for help enabling promiscuous mode in the virtual machine.

promiscuous
a. 淫乱的;滥交的;大杂烩的;杂乱的

  • SSH。

SSH 端口:22
Linux 中守护进程:sshd。
安装服务:OpenSSH。
服务端主程序:/usr/sbin/sshd
客户端主程序:/usr/bin/ssh

[root@localhost ~]# ps aux | grep sshd
root       1281  0.0  0.1  66288  1204 ?        Ss   18:44   0:00 /usr/sbin/sshd
root       1420  0.0  0.4 102132  4144 ?        Ss   18:45   0:00 sshd: root@pts/0 
root       1437  0.0  0.0 103320   884 pts/0    S+   18:55   0:00 grep sshd
[root@localhost ~]# netstat -ltnu | grep 22
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
[root@localhost ~]# 
  • 相关文件。

服务端配置文件。—> /etc/ssh/sshd_config。
客户端配置文件。—> /etc/ssh/ssh_config。



SSH 远程管理服务。

SSH 加密原理。
  • 对称加密算法。

采用单钥密码系统的加密方法,同一个密钥可以同时用作信息的加密和解密,这种加密方法称为对称加密,也称为单密钥加密

  • 非对称加密算法。

非对称加密算法(asymmetric cryptographic algorithm)又名公开密钥加密算法,非对称加密算法需要两个密钥:公开密钥(publickey)私有密钥(privatekey)

软件。
pgp —> Windows。
gpg —> LInux。

公钥 —> 锁。
私钥 —> 钥匙。

ssh 第一次登录 —> 下载服务器端公钥。
ssh-dsa 1024 + …
ssh 加密:1024 位。—> 只保护传输过程。如果中途被截获,乱码。

公钥存放位置:~/.ssh/known_hosts。



SSH 配置原理。

服务端配置文件。—> /etc/ssh/sshd_config。
客户端配置文件。—> /etc/ssh/ssh_config。

  • /etc/ssh/sshd_config。
Port 22									# 端口。
ListenAddress 0.0.0.0					# 监听的 IP。
Protocol 2								# SSH 版本选择。
HostKey /etc/ssh/ssh_host_rsa_key		# 私钥保存位置。
ServerKeyBits 1024						# 私钥的位数。
SyslogFacility AUTH						# 日志记录 SSH 登陆情况。
LogLevel INFO							# 日志等级。
GSSAPIAuthentication yes				# GSSAPI 认证开启。

配置文件中都是默认注释状态。
建议改端口。22。 都知道。
0.0.0.0 —> 监听任何 IP。
Protocol 2 —> 默认没有被注释。
1 和 2 代 ssh 默认 HostKey 保存位置文件不同。
日志记录位置:/var/log/secure。

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

GSSAPIAuthentication yes # GSSAPI 认证开启。

会尝试把当前计算机 IP 翻译成主机名,需要 DNS 服务。
如果没有配置 DNS 服务器,登录输入密码后会等待较长时间。
一般建议将客户端的 GSSAPIAuthentication 设为 no。



安全设定部分。
PermitRootLogin yes											# 允许 root 的 ssh 登陆。
PubkeyAuthenyication yes									# 是否使用公钥验证。
AuthorizedKeysFile   .ssh/authorized_keys		# 公钥的保存位置。
PasswordAuthentication yes								# 允许使用密码验证
PermitEmptyPasswords no									# 不允许空密码登陆。
[root@localhost ~]# service sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd: 
geek@geek-PC:~$ ssh root@192.168.223.129
root@192.168.223.129's password: 
Permission denied, please try again.

但可以通过 su 切换用户。

要安全,应该彻底关闭密码登录,使用密钥登录。



常用 SSH 命令。
  • SSH 远程管理。

ssh 用户名@IP

  • scp 远程复制。
    • 下载。

scp root@192.168.233.129:/home/geek/scp_test.txt /hemo/geek

geek@geek-PC:~$ scp root@192.168.223.129:/home/geek/scp_test.txt .  # 到本地本目录。
root@192.168.223.129's password: 
scp_test.txt                                    100%    0     0.0KB/s   00:00    
geek@geek-PC:~$ 
  • 上传。

scp -r ./visudo.txt root@192.168.223.129:/home/geek
上传目录要加 -r。

geek@geek-PC:~/geek$ scp -r ./visudo.txt root@192.168.223.129:/home/geek
root@192.168.223.129's password: 
visudo.txt                                      100% 1335     3.6MB/s   00:00    
  • Sftp 文件传输。

sftp root@138.168.223.129 # 进入交互模式。
-ls 。 —> 查看服务器端目录。
-cd 。 —> 切换服务器端目录。
-lls 。 —> 查看本地数据。
-lcd 。 —> 切换本地目录。
-get 。 —> 下载。
-put 。 —> 上传。

geek@geek-PC:~/geek$ sftp root@192.168.223.129
root@192.168.223.129's password: 
Connected to 192.168.223.129.
sftp> 

[root@localhost geek]# sftp root@192.168.223.129
Connecting to 192.168.223.129...
The authenticity of host '192.168.223.129 (192.168.223.129)' can't be established.
RSA key fingerprint is d3:af:8c:eb:94:8f:f9:44:b6:be:ac:e3:a5:7a:00:d3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.223.129' (RSA) to the list of known hosts.
root@192.168.223.129's password: 
sftp> 

sftp> ls
sftp> lls
sftp> cd
sftp> lcd

l —> local.


SSH 连接工具。

SSH 命令是针对 Linux 去连接远程 Linux。
如果要用 Windows 远程连接 Linux 服务器。

  • 虚拟机内的 Linux 内用 SSH 命令。
  • 工具。(SecureCRT 、 PuTTY 、 XShell)。


密钥对登陆。
  • 由客户端用户 geek 在本地创建密钥对。

    私钥文件:id_rsa
    

    公钥文件:id_rsa.pub

  • 上传公钥文件 id_rsa.pub。

  • 导入到服务器端用户 geek 的公钥信息。

    公钥库文件:~/.ssh/authorized_keys
    [root@localhost ~]# ll ~/.ssh/known_hosts
    -rw-r–r–. 1 root root 397 Feb 18 20:43 /root/.ssh/known_hosts

  • 使用密钥对验证方式。

    以服务端的用户 geek 的身份进行登录。(这个公钥匹配到谁的 authorized_keys 就以谁的身份登录)。
    (~/.ssh/authorized_keys —> ~ 指用户的家目录。如果是 geek 用户, ~ 就是指 geek 的家目录)。


  • client 端
geek@geek-PC:~/geek/ssh_demo$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/geek/.ssh/id_rsa): .
. already exists.
Overwrite (y/n)? n
geek@geek-PC:~/geek/ssh_demo$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/geek/.ssh/id_rsa): .
. already exists.
Overwrite (y/n)? n
geek@geek-PC:~/geek/ssh_demo$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/geek/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/geek/.ssh/id_rsa.
Your public key has been saved in /home/geek/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zx1qE+JkNz9bEcbML3y5bLDwdWkC32EibmqCWcS02R4 geek@geek-PC
The key's randomart image is:
+---[RSA 2048]----+
|       .         |
|      o +    +   |
|       = E o .*o |
|      . . o +o+o+|
|       .S.++.++*+|
|      ++ =o*o.B+o|
|     o ..o* +o.+ |
|        o. . +.  |
|            .    |
+----[SHA256]-----+


geek@geek-PC:~/.ssh$ ls
id_rsa  id_rsa.pub  known_hosts


  • server 端。

把公钥上传到服务器端。

geek@geek-PC:~/.ssh$ scp id_rsa.pub root@192.168.223.129:/root
root@192.168.223.129's password: 
id_rsa.pub                                      100%  394     1.1MB/s   00:00    
geek@geek-PC:~/.ssh$ 

用 server 端。

[root@localhost ~]# cat id_rsa.pub >> /root/.ssh/authorized_keys
[root@localhost ~]# ll /root/.ssh/
total 8
-rw-r--r--. 1 root root 394 Feb 18 21:41 authorized_keys
-rw-r--r--. 1 root root 397 Feb 18 20:43 known_hosts
[root@localhost ~]# chmod 600 /root/.ssh/authorized_keys 
# 默认 644。
# 此操作是必选项。
# 因为 644 权限任何用户都可以读, SELinux 服务不同意。限制。

运用 >> 方法而不是 mv 是因为可能不止一台机器需要。>> 可追加多个。

SELinux 服务对系统中所有服务影响很大,建议关闭。
SELINUX=enforcing 改为 disabled。

vi /etc/selinux/confiig

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted


~                                                                                 
~                                                                                 
~                                                                                 
"/etc/selinux/config" 13L, 458C

  • 修改服务器端 ssh 配置文件。

vi /etc/ssh/sshd_config

  • RSAAuthentication yes # 开启 RSA 验证。
  • PubkeyAuthentication yes # 是否使用公钥验证。
  • AuthorizedKeysFile .ssh/authorized_keys # 公钥的保存位置。
  • PasswordAuthentication no # 禁止使用密码验证登陆。
  • service sshd restart

比防火墙灵活(公司电脑连服务器,回家后用个人电脑,被防火墙。可以设置路由解决,但非常麻烦)。
私钥丢失就 gg。

  • Windows 上,远程工具导入私钥文件。
login as: root
Authenticating with public key "geek@geek-PC" from agent
Last login: Tue Feb 18 22:18:48 2020 from 192.168.223.1
[root@localhost ~]#


DHCP 服务。

  • DHCP 简介与原理。
  • DHCP 服务器相关文件。
  • 配置文件。
  • 配置 DHCP 服务器。


DHCP 简介与原理。
  • Dynamic Host Configuration Protocol。动态主机配置协议。
    为大量客户机自动分配地址,提供集中管理。
    减轻管理和维护成本,提高网络配置效率。

可分配的地址信息主要包括。

  • 网卡的 IP 地址、子网掩码。
  • 对应的网络地址、广播地址。
  • 默认网关地址。
  • DNS 服务器地址。
  • 引导文件、TFTP 服务器地址。

一般,客户机和 DHCP 要在同一网段。

在这里插入图片描述

  • 客户端寻找服务器。
    发送数据包问 ip,Windows 7 以前会一直发,如果没有 DHCP 服务器,Windows 7 以后会给自己一个假的 IP。
  • 服务器提供地址信息。
    如果局域网内有 Linux 和 Windows 服务器都搭建了 DHCP 服务器,优先去 Windows 服务器获取。
  • 接受并广播。
    使用第一个回复的 ip。
  • 服务器确认。
  • 客户端重新登录。
  • 服务器确认。


相关文件。

[root@localhost ~]# yum install dhcp

端口。
  • ipv4。

udp ~ 67。
udp ~ 68。

  • ipv6。

udp ~ 546。
udp ~ 547。



相关文件。
  • 服务名:dhcpd。

  • 主配置文件:/etc/dhcp/dhcpd.conf。

  • 模板文件:/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample。

[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
cp: overwrite `/etc/dhcp/dhcpd.conf’? y

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#

[root@localhost ~]# cat /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample 
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

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 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.

subnet 10.152.187.0 netmask 255.255.255.0 {
}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
  range 10.5.5.26 10.5.5.30;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.31;
  default-lease-time 600;
  max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

host passacaglia {
  hardware ethernet 0:0:c0:5d:bd:95;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
}

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address fantasia.fugue.com;
}

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

class "foo" {
  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}

shared-network 224-29 {
  subnet 10.17.224.0 netmask 255.255.255.0 {
    option routers rtr-224.example.org;
  }
  subnet 10.0.29.0 netmask 255.255.255.0 {
    option routers rtr-29.example.org;
  }
  pool {
    allow members of "foo";
    range 10.17.224.10 10.17.224.250;
  }
  pool {
    deny members of "foo";
    range 10.0.29.10 10.0.29.230;
  }
}
[root@localhost ~]# 



配置。
option domain-name				# 所在 DNS 域。
option domam-name server		# DNS 服务器地址。
default-lease-time				# 默认租约时间,单位为秒。
max-lease-time					# 最大租约时间,单位为秒。
log-facility					# 指定日志设备。
ddns-update-style				# DNS 的更新方式。
authoritative					# 标识权威服务器。(如果有多台 DHCP 服务器)。
log-facility Iocal7				# 日志发送到 local7 日志服务中。
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

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 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.

subnet 10.152.187.0 netmask 255.255.255.0 {
}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
  range 10.5.5.26 10.5.5.30;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.31;
  default-lease-time 600;
  max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

host passacaglia {
  hardware ethernet 0:0:c0:5d:bd:95;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
}

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address fantasia.fugue.com;
}

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

class "foo" {
  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}

shared-network 224-29 {
  subnet 10.17.224.0 netmask 255.255.255.0 {
    option routers rtr-224.example.org;
  }
  subnet 10.0.29.0 netmask 255.255.255.0 {
    option routers rtr-29.example.org;
  }
  pool {
    allow members of "foo";
    range 10.17.224.10 10.17.224.250;
  }
  pool {
    deny members of "foo";
    range 10.0.29.10 10.0.29.230;
  }
}
[root@localhost ~]# 

[root@localhost ~]# cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak
// # 备份。
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers 223.5.5.5, 223.6.6.6;

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 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.

# A slightly different configuration for an internal subnet.
subnet 192.168.142.0 netmask 255.255.255.0 {
  range 192.168.142.50 192.168.142.200;
  option routers 192.168.142.1;
  option broadcast-address 192.168.142.255;
  default-lease-time 600;
  max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

[root@localhost ~]# service dhcpd restart
Starting dhcpd:                                            [  OK  ]



客户端。
  • vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=dhcp

service network restart

cat /var/lib/dhcpd/dhcpd.leases



vsftp。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lyfGeek

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值