« Отговор #34 -: Mar 28, 2010, 16:12 »
Наскоро правих нещо подобно. След като тръгна сървъра събрах упътванията в една страница. По принцип е за Убунту сървър, ама може да ти е от полза. Това упътване при мен е напълно работещо, без допълнителни настройки. "eth0" е клиент на рутера, "eth1" раздава адресите на локалната мрежа.
Единствено след като инсталираш DHCP трябва да промениш файла /etc/dhcp3/dhcpd.conf да изглежда примерно така:
# Sample /etc/dhcpd.conf
# (add your comments here)
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.10.255;
option routers 192.168.10.1;
option domain-name-servers 192.168.1.1;
#option domain-name "mydomain.example";
option netbios-name-servers 192.168.10.1;
option netbios-node-type 2;
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.10 192.168.10.100;
}
# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;
Network Interface Cards
DHCP Server
Install
First install the dhcp3-server package
apt-get install dhcp3-server
Manual Static Address
The first step is to make sure that your internal network functions. You should setup your second Ethernet wired or wireless card and set its IP address to something like "192.168.10.1" via ifconfig utility as follows:
ifconfig eth1 192.168.10.1 netmask 255.255.255.0
Automatic Static Address
This setup will be forgotten after a reboot, its better to add these lines to /etc/network/interfaces (replacing any previous declarations of eth1):
nano -w /etc/network/interfaces
# The extended interfaces
auto eth1
iface eth1 inet static
address 192.168.10.1
netmask 255.255.255.0
Testing Static Configuratiom
Check if the previous command worked by typing the following:
ifconfig
The result will look like this
ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:6E:8A:BD:ED
inet addr:192.168.1.64 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:6eff:fe8a:bded/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:80071 errors:0 dropped:0 overruns:0 frame:0
TX packets:44847 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:119404142 (113.8 MB) TX bytes:3332468 (3.1 MB)
Interrupt:20
eth1 Link encap:Ethernet HWaddr 00:20:18:3A:4E:AE
inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::220:18ff:fe3a:4eae/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2092 errors:0 dropped:0 overruns:0 frame:17
TX packets:1998 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:158939 (155.2 KB) TX bytes:348453 (340.2 KB)
Interrupt:16 Base address:0xa800
Assign Network Card
One more thing needs to be configured before we can run the DHCP server Open the file /etc/default/dhcp3-server
nano -w /etc/default/dhcp3-server
# Defaults for dhcp initscript
# sourced by /etc/init.d/dhcp
# installed at /etc/default/dhcp3-server by the maintainer scripts
#
# This is a POSIX shell fragment
#
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1″.
INTERFACES="eth1"
Explanation: Like the comment it the file says we are specifying the network card which must be used to handle dhcp requests
Finally the setup is done!
Start DHCP server
So lets run the DHCP server with:
/etc/init.d/dhcp3-server start
* Starting DHCP server dhcpd3
done.
If it report fails then look at the error log file ($ less /var/log/syslog and press END to view the last events)
Configure NAT
Configure iptables for NAT translation so packets can be correctly routed through the Ubuntu gateway.
sudo iptables -A FORWARD -i eth1 -o eth0 -s 192.168.10.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A POSTROUTING -t nat -j MASQUERADE
(rule1 allows forwarded packets (initial ones), rule2 allows forwarding of established connection packets (and those related to ones that started), rule3 does the NAT.)
Enable routing
* Configure the gateway for routing between two interfaces by enabling IP forwarding:
sudo -i
sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
su user
* Edit /etc/sysctl.conf and add these lines:
net.ipv4.conf.default.forwarding=1
net.ipv4.conf.all.forwarding=1
The /etc/sysctl.conf edit is required because of following Bug (Hardy and later releases) Launchpad Bug Report
Load Firewall Rule
To load our new firewall rule on a reboot.
nano -w /etc/network/interfaces
replacing any previous declarations of eth0
# The extended interfaces
auto eth0
iface eth0 inet dhcp
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
Interfaces Config File
The complete file /etc/network/interfaces should look like this after all the modifications we applied:
# 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
# The primary network interface
auto eth0
iface eth0 inet dhcp
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
# The extended interfaces
auto eth1
iface eth1 inet static
address 192.168.10.1
netmask 255.255.255.0
Special Note
Never do:
apt-get remove ipmasq
Its a stupid thing we learned during testing, this will result in a LOT of malfunctions, so make sure you don’t do stupid things like we did!
Дотук би трябвало да имаш работещ DHCP сървър на "eth1" с форуърдинг и маскарадинг.