-------------------------------------------------------------------
Static IP address
Edit
/etc/network/interfaces
and adjust it to your needs (in this example setup I will use the IP address 192.168.0.100):
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
script grep
map eth0
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
Then do
sudo /etc/init.d/networking restart
to restart the network.
-------------------------------------------------------------------
DHCP Server (Ubuntu)
1. What is a DHCP Server?
2. How do I install a DHCP Server?
1.
What is a DHCP Server?
A Dynamic Host Configuration Protocol (DHCP) server dynamically assigns IP addresses and other network setting for a given network to other networked PCs that ask. This simplifies network administration and makes connecting new PCs to a network much easier.
2.
How do I install a DHCP Server?
For these examples we are using “eth0” and the following:
IP address range: 192.168.0.100 to 192.168.0.200
Subnet Mask: 255.255.255.0
DNS Servers: 202.188.0.133, 202.188.1.5
Domains: tm.net.my
Gateway Address: 192.168.0.1
Read How do I add Universe and Multiverse?
Install the dhcp3-server package with Synaptic(See How do I use Synaptic to install packages?)
Networking > dhcp3-server
sudo cp /etc/default/dhcp3-server /etc/default/dhcp3-server_backup
sudo gedit /etc/default/dhcp3-server
Find this line
... INTERFACES=""
Replace with the following line
INTERFACES="eth0"
Save the edited file (How do I install a DHCP Server?)
sudo cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf_backup
sudo gedit /etc/dhcp3/dhcpd.conf
Find this section
...
# 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;
...
Replace with the following lines
# 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;
Find this section
...
# 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;
#}
...
Replace with the following lines
# A slightly different configuration for an internal subnet.
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200;
option domain-name-servers 202.188.0.133, 202.188.1.5;
option domain-name "tm.net.my";
option routers 192.168.0.1;
option broadcast-address 192.168.0.255;
default-lease-time 600;
max-lease-time 7200;
}
Save the edited file (sample/dhcpd.conf_installdhcpserver)
sudo /etc/init.d/dhcp3-server restart
-------------------------------------------------------------------
Configuring a DHCP Client (CentOS)
The first step for configuring a DHCP client is to make sure the kernel recognizes the network interface card. Most cards are recognized during the installation process and the system is configured to use the correct kernel module for the card. If a card is added after installation, Kudzu [9] will recognize it and prompt you for the proper kernel module (Be sure to check the Hardware Compatibility List at http://hardware.redhat.com/hcl/). If either the installation program or kudzu does not recognize the network card, you can load the correct kernel module (refer to Chapter 40, General Parameters and Modules for details).
To configure a DHCP client manually, modify the /etc/sysconfig/network file to enable networking and the configuration file for each network device in the /etc/sysconfig/network-scripts directory. In this directory, each device should have a configuration file named ifcfg-eth0, where eth0 is the network device name.
The /etc/sysconfig/network file should contain the following line:
NETWORKING=yes
The NETWORKING variable must be set to yes if you want networking to start at boot time.
The /etc/sysconfig/network-scripts/ifcfg-eth0 file should contain the following lines:
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
A configuration file is needed for each device to be configured to use DHCP.
Other options for the network script includes:
DHCP_HOSTNAME — Only use this option if the DHCP server requires the client to specify a hostname before receiving an IP address. (The DHCP server daemon in Red Hat Enterprise Linux does not support this feature.)
PEERDNS=<answer>, where <answer> is one of the following:
yes — Modify /etc/resolv.conf with information from the server. If using DHCP, then yes is the default.
no — Do not modify /etc/resolv.conf.
SRCADDR=<address>, where <address> is the specified source IP address for outgoing packets.
USERCTL=<answer>, where <answer> is one of the following:
yes — Non-root users are allowed to control this device.
no — Non-root users are not allowed to control this device.
If you prefer using a graphical interface, refer to Chapter 14, Network Configuration for instructions on using the Network Administration Tool to configure a network interface to use DHCP.
Tip
For advanced configurations of client DHCP options such as protocol timing, lease requirements and requests, dynamic DNS support, aliases, as well as a wide variety of values to override, prepend, or append to client-side configurations, refer to the dhclient and dhclient.conf man pages.
[9] Kudzu is a hardware probing tool run at system boot time to determine what hardware has been added or removed from the system.
-------------------------------------------------------------------
注:使用虚拟机时需要将网络设置为桥接,不能选择NAT
转载于:https://blog.51cto.com/linuxlearner/204344