基于linux下的虚拟机里 dhcp安装、动态网络编辑、及其ip的获取
1、hostnamectl 查看是哪个系统
2、建立iso 镜像目录
mkdir /iso/
3、复制镜像文件到iso目录下
scp [email protected]:/home/kiosk/Desktop/rheL-server-7.0* /iso
4、建立source7.0
mkdir /source7.0
5、挂载镜像文件到source7.0
mount /iso/rhe*7.0 /source7.0
6、编辑文件
vim /etc/yum.repos.d/yum.repo
编辑文件的内容如下
[source7.0]
name=source7.0
baseurl=file:///source7.0
gpgcheck=0
7、安装dhcp
yum search dhcp 查询dhcp
yum install dhcp.x86_64 -y 安装dhcp,-y的意思是安装时不需要提醒是否是否需要安装
8、切换到/etc/dhcp目录下
cd /etc/dhcp
9、复制文件到/etc/dhcp/dhcpd.conf下
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
10、查看/etc/dhcp下有什么文件
ls 有三个文件
11、编辑文件
vim /etc/dhcp/dhcpd.conf
编辑文件
将文件的第7行和第8行进行修改为
7 option domain-name "example.com";
8 option domain-name-servers 114.114.114.114;
并删除27行
并将32 -35行修改为
32 subnet 172.25.254.0 netmask 255.255.255.0 {
33 range 172.25.254.100 172.25.254.110; #ip的范围
34 option routers 172.25.254.250;
35 }
将后面的删除
12、cat /var/lib/dhcpd/dhcpd.leases #查看获得的ip从哪里来的
练习
[[email protected] ~]# mkdir /iso
[[email protected] ~]# scp [email protected]:/home/kiosk/Desktop/rhel-server-7.0-x86_64-dvd.iso /iso
[email protected]'s password:
rhel-server-7.0-x86_64-dvd.iso 100% 3570MB 33.1MB/s 01:48
[[email protected] ~]#
[[email protected] ~]# mkdir /source7.0
[[email protected] ~]# mount /iso/rhel-server-7.0-x86_64-dvd.iso /source7.0
mount: /dev/loop0 写保护,将以只读方式挂载
[[email protected] ~]# ls /iso
rhel-server-7.0-x86_64-dvd.iso
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vim yum.repo
[source7.0]
name=source7.0
baseurl=file:///source7.0
gpgcheck=0
[[email protected] ~]# yum search dhcp #查询dhcp的安装包
已加载插件:langpacks
======================== N/S matched: dhcp ========================
dhcp-common.x86_64 : Common files used by ISC dhcp client and
: server
dhcp-libs.i686 : Shared libraries used by ISC dhcp client and
: server
dhcp-libs.x86_64 : Shared libraries used by ISC dhcp client and
: server
dhclient.x86_64 : Provides the ISC DHCP client daemon and
: dhclient-script
dhcp.x86_64 : Dynamic host configuration protocol software
dnsmasq.x86_64 : A lightweight DHCP/caching DNS server
名称和简介匹配 only,使用“search all”试试。
[[email protected] ~]# yum install dhcp.x86_64 -y #安装dhcp.x86_64 安装包,-y的意思是不需要任何提示,直接安装
[[email protected] yum.repos.d]# cd /etc/dhcp
[[email protected] dhcp]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[[email protected] dhcp]# ls
dhclient.d dhcpd6.conf dhcpd.conf
[[email protected] dhcp]# vim dhcpd.conf
[[email protected] dhcp]# systemctl start dhcpd #开启dhcpd服务
[[email protected] dhcp]# systemctl enable dhcpd #开机启动dhcp服务
ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service'
编辑dhcpd.conf文件
1 # dhcpd.conf
2 #
3 # Sample configuration file for ISC dhcpd
4 #
5
6 # option definitions common to all supported networks...
7 option domain-name "example.com";
8 option domain-name-servers 114.114.114.114;
9
10 default-lease-time 600;
11 max-lease-time 7200;
12
13 # Use this to enble / disable dynamic dns updates globally.
14 #ddns-update-style none;
15
16 # If this DHCP server is the official DHCP server for the local
17 # network, the authoritative directive should be uncommented.
18 #authoritative;
19
20 # Use this to send dhcp log messages to a different log file (you also
21 # have to hack syslog.conf to complete the redirection).
log-facility local7;
23
24 # No service will be given on this subnet, but declaring it helps the
25 # DHCP server to understand the network topology.
26
30 # This is a very basic subnet declaration.
31
32 subnet 172.25.254.0 netmask 255.255.255.0 {
33 range 172.25.254.100 172.25.254.110;
34 option routers 172.25.254.250;
35 };
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.10 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::5054:ff:fe00:3c0a prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:3c:0a txqueuelen 1000 (Ethernet)
RX packets 239444 bytes 3767481070 (3.5 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 154388 bytes 12319181 (11.7 MiB)
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 0 (Local Loopback)
RX packets 348 bytes 51000 (49.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 348 bytes 51000 (49.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、建立iso 镜像目录
mkdir /iso/
3、复制镜像文件到iso目录下
scp [email protected]:/home/kiosk/Desktop/rheL-server-7.0* /iso
4、建立source7.0
mkdir /source7.0
5、挂载镜像文件到source7.0
mount /iso/rhe*7.0 /source7.0
6、编辑文件
vim /etc/yum.repos.d/yum.repo
编辑文件的内容如下
[source7.0]
name=source7.0
baseurl=file:///source7.0
gpgcheck=0
7、安装dhcp
yum search dhcp 查询dhcp
yum install dhcp.x86_64 -y 安装dhcp,-y的意思是安装时不需要提醒是否是否需要安装
8、切换到/etc/dhcp目录下
cd /etc/dhcp
9、复制文件到/etc/dhcp/dhcpd.conf下
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
10、查看/etc/dhcp下有什么文件
ls 有三个文件
11、编辑文件
vim /etc/dhcp/dhcpd.conf
编辑文件
将文件的第7行和第8行进行修改为
7 option domain-name "example.com";
8 option domain-name-servers 114.114.114.114;
并删除27行
并将32 -35行修改为
32 subnet 172.25.254.0 netmask 255.255.255.0 {
33 range 172.25.254.100 172.25.254.110; #ip的范围
34 option routers 172.25.254.250;
35 }
将后面的删除
12、cat /var/lib/dhcpd/dhcpd.leases #查看获得的ip从哪里来的
练习
[[email protected] ~]# mkdir /iso
[[email protected] ~]# scp [email protected]:/home/kiosk/Desktop/rhel-server-7.0-x86_64-dvd.iso /iso
[email protected]'s password:
rhel-server-7.0-x86_64-dvd.iso 100% 3570MB 33.1MB/s 01:48
[[email protected] ~]#
[[email protected] ~]# mkdir /source7.0
[[email protected] ~]# mount /iso/rhel-server-7.0-x86_64-dvd.iso /source7.0
mount: /dev/loop0 写保护,将以只读方式挂载
[[email protected] ~]# ls /iso
rhel-server-7.0-x86_64-dvd.iso
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vim yum.repo
[source7.0]
name=source7.0
baseurl=file:///source7.0
gpgcheck=0
[[email protected] ~]# yum search dhcp #查询dhcp的安装包
已加载插件:langpacks
======================== N/S matched: dhcp ========================
dhcp-common.x86_64 : Common files used by ISC dhcp client and
: server
dhcp-libs.i686 : Shared libraries used by ISC dhcp client and
: server
dhcp-libs.x86_64 : Shared libraries used by ISC dhcp client and
: server
dhclient.x86_64 : Provides the ISC DHCP client daemon and
: dhclient-script
dhcp.x86_64 : Dynamic host configuration protocol software
dnsmasq.x86_64 : A lightweight DHCP/caching DNS server
名称和简介匹配 only,使用“search all”试试。
[[email protected] ~]# yum install dhcp.x86_64 -y #安装dhcp.x86_64 安装包,-y的意思是不需要任何提示,直接安装
[[email protected] yum.repos.d]# cd /etc/dhcp
[[email protected] dhcp]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[[email protected] dhcp]# ls
dhclient.d dhcpd6.conf dhcpd.conf
[[email protected] dhcp]# vim dhcpd.conf
[[email protected] dhcp]# systemctl start dhcpd #开启dhcpd服务
[[email protected] dhcp]# systemctl enable dhcpd #开机启动dhcp服务
ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service'
编辑dhcpd.conf文件
1 # dhcpd.conf
2 #
3 # Sample configuration file for ISC dhcpd
4 #
5
6 # option definitions common to all supported networks...
7 option domain-name "example.com";
8 option domain-name-servers 114.114.114.114;
9
10 default-lease-time 600;
11 max-lease-time 7200;
12
13 # Use this to enble / disable dynamic dns updates globally.
14 #ddns-update-style none;
15
16 # If this DHCP server is the official DHCP server for the local
17 # network, the authoritative directive should be uncommented.
18 #authoritative;
19
20 # Use this to send dhcp log messages to a different log file (you also
21 # have to hack syslog.conf to complete the redirection).
log-facility local7;
23
24 # No service will be given on this subnet, but declaring it helps the
25 # DHCP server to understand the network topology.
26
30 # This is a very basic subnet declaration.
31
32 subnet 172.25.254.0 netmask 255.255.255.0 {
33 range 172.25.254.100 172.25.254.110;
34 option routers 172.25.254.250;
35 };
将其ip设置为动态获取
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.10 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::5054:ff:fe00:3c0a prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:3c:0a txqueuelen 1000 (Ethernet)
RX packets 239444 bytes 3767481070 (3.5 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 154388 bytes 12319181 (11.7 MiB)
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 0 (Local Loopback)
RX packets 348 bytes 51000 (49.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 348 bytes 51000 (49.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0