In large enterprise network architecture ,Routers usually cannot assign ip, because that don’t support a service named DHCP.
What does the DHCP mean? That is a service assign ip to every network equipment. We don’t need to config ip to each network equipment.
Knowledge
What does IP?
IP like a network equipment’s ID card. Every equipment have different IP(In public network).Sometimes, we can find some network equipment use the same IP, Why?
- They use keepalived to set up Virtual IP (VIP)
- They are don’t in the same lan.
For the frist point, That is a HA solution. If one server shut down, another server will preemption that VIP.
Keepalived cluster is depend an agreement named VRRP. If master is normal operation,master will send a VRRP broadcast package ,the slave cant’t preemption that VIP.
For the second point. If you want understand this sentence ,you need get to know what is VLAN and LAN.
VLAN is similar to LAN.LAN can divide to many VLAN. Each vlan cannot be connected to each other. LAN is same ad VLAN ,too.
What does gateway mean?
Gateway is a equipment,which can forward data to Internet.In lan,there is always have one gateway.All network enquiment send data to gateway.so,gateway is the necessary(必须的) part.
What does netmask?
As we know,IP is divided into four segments,they can be expressed as a 32-bit binary number.We can use netmask to regulation which is segment number,which is host number.
What does MAC?
MAC is ethernet drive’s physical address .Like 00:0C:29:E3:2A:D1
.Every network equimpent have different MAC.
Install DHCP service
We can use yum to install DHCP.
yum install dhcp
Let me see the dhcp’s config file tree.
[root@localhost network-scripts]# tree /etc/dhcp/
/etc/dhcp/
├── dhclient.d
│ └── chrony.sh
├── dhclient-exit-hooks.d
│ └── azure-cloud.sh
├── dhcpd6.conf
├── dhcpd.conf
└── scripts
└── README.scripts
We should copy default config file in this directory.
cp /usr/share/doc/dhcp*/dhcpd.conf.example ./dhcpd.conf
Edit that file:
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.89.0 netmask 255.255.255.0 {
range 192.168.89.100 192.168.89.200;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 192.168.89.2;
option broadcast-address 192.168.89.255;
default-lease-time 600;
max-lease-time 7200;
}
There is some import key:
“option domain-name” and “option domain-name-services” is bind a domain-name to dhcp service.
lease-time: That is the ip lease time.If the lease expires,DHCP will assign again.
subnet 192.168.89.0 netmask 255.255.255.0
: There set the network segment and netmask.
range: That is ip’s range.
option routers
and option broadcast-address
: There routes have the same mean with gateway.and ,broadcast-address we always use this network segment’s the last ip.
OK,base environment install success.
Bind static ip
We always bind ip to ethernet (MAC).Add a model to dhcpd.conf.
host xp {
hardware ethernet 00:0C:29:E3:2A:D1;
fixed-address 192.168.89.111;
}
We can use any host name you want.but ,that is only allowed to be used once.
hardware ethernet
is bind a MAC address.fixed-address
is bind a ip to that MAC.
Restart dhcp and restart slave copmouter network.We can find that IP was changed.
That’s all.
Thanks.
Reference:
[1] Liu Chuan.Linux 就该这么学[M].北京:人民邮电出版社出版,2017年∶270-276