About how to configure and use DHCP in linux-Linux Enterprise Application-Linux server application information. The following is a detailed description. As for the function of DHCP, no more examples are needed. For me, a single sentence is to allow the client to automatically obtain IP address information.
What if DHCP is used? For example, if you manage a LAN, the local computer must be able to access the Internet. At this time, you must set the IP address information for the computer that can access the Internet. Of course, if the number of computers is small, it will not take much time to complete the configuration. However, for example, there are too many computers and hundreds of computers.
Although you can set IP information for one ECs instance, it takes too much time to complete it using DHCP.
Take LINUX/debian as an example. First, use the following method to install dhcp.
Apt-get install dhcp
Then, DHCP is configured. The DHCP master configuration file is stored in/etc/dhcp. in conf, configure domain name DNS, Client IP address range, gateway, and lease period.
After the configuration is complete, restart the DHCP server and pay attention to the following issues:
1) if the host only has one NIC (eth0), you can restart the instance by using/etc/init. d/dhcp restart. Then the client can automatically obtain IP information.
2) if the host has two or more NICs, you must specify to start from the NIC connected to the LAN. Assume that network adapter 1 (eth0) is connected to the Internet, and network adapter 2 (eth1) is connected to the Intranet, restart with/usr/sbin/dhcp restart.
The above is to allow the client to automatically obtain IP information, but the rest is that the client can access the Internet. In LINUX, I can use iptables as a route to drive local and internal clients to access the Internet. The installation of Iptables is the same as that of dhcp. For simple control, iptables does not need to be configured. Iptables is directly used to drive the internet cafe on the client.
Preparation: Before applying iptables, check whether echo "1">/proc/sys/net/ip_forward exists. In this case, the kernel forwarding function is enabled.
Method 1:
/Sbin/iptables? T nat? A postrouting? O ppp0? J MASQUERADE
The above uses the ppp method for Internet access. If the LAN uses a fixed IP address, assume that the IP address is 222.33.44.55 (that is, the eth0 address of the egress Nic, which is shown below), you need to use the following method:
/Sbin/iptables? T nat? A postrouting? O eth0? J SNAT? To 222.33.44.55
Method 2: Use shell with iptables
File Content:
A: dynamic mode
#! /Bin/sh
IPTABLES = "/sbin/iptables"
IFACE = "PPP0"
$ IPTABLES? T nat? A postrouting? O $ IFACE? J MASQUERADE
B: static mode:
#! /Bin/sh
IPTABLES = "/sbin/iptables"
IFACE = "eth0"
$ OUT_IP = "222.33.44.55"
$ IPTABLES? T nat? A postrouting? O $ IFACE? J SNAT? To $ OUT_IP
Method 3: more user-friendly (static)
#! /Bin/sh
IPTABLES = "/sbin/iptables"
Echo "Enter the exit interface"
Read IFACE
Echo "Enter the exit address"
Read OUT_IP
$ IPTABLES? T nat? A postrouting? O $ IFACE? J SNAT? To $ OUT_IP
You can also perform more optimization on method 3, such as directly listing the export name and selecting the input interface data. I will not give an example here. If you are familiar with shell, all this can be changed.
The above content is rough. If there is anything wrong or something wrong, please correct me! For reference only.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service