sudo nano /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.20.30.77
netmask 255.255.255.0
gateway 10.20.30.1
network 10.20.30.0
broadcast 10.20.30.255
dns-nameservers 10.20.30.15 10.20.30.16
dns-search codeghar.com
auto eth1
iface eth1 inet static
address 172.22.22.1
netmask 255.255.255.0
network 172.22.22.0
broadcast 172.22.22.255
แก้ไขไฟล์ /etc/sysctl.conf เพื่อเปิดใช้งาน IPv4 forwarding
sudo nano /etc/sysctl.conf
โดยเอาเครื่องหมาย # บรรทัดนี้ออก
# net.ipv4.ip_forward=1
จะได้ดังนี้
net.ipv4.ip_forward=1
Save ไฟล์และรันคำสั่งต่อไปนี้เพื่อให้ทำงานโดยไม่ต้อง reboot
sudo sysctl -w net.ipv4.ip_forward=1
/etc/rc.local
ทำการ allow iptables rules เพื่อทำ NAT โดยแก้ไขไฟล์ดังนี้
sudo nano /etc/rc.local
เพิ่มสองบรรทัดนี้ลงไป
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE
สั่งให้คำสั่งทำงานก่อนโดยไม่ต้อง reboot
sudo iptables -P FORWARD ACCEPT
sudo iptables –-table nat -A POSTROUTING -o eth0 -j MASQUERADE
Install DHCP server
sudo aptitude install isc-dhcp-server
/etc/dhcp/dhcpd.conf
sudo vim /etc/dhcp/dhcpd.conf
ddns-update-style none;
# option definitions common to all supported networks...
option domain-name "codeghar.com";
option domain-name-servers 10.20.30.15, 10.20.30.16;
default-lease-time 3600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# This is a very basic subnet declaration.
subnet 172.22.22.0 netmask 255.255.255.0 {
range 172.22.22.21 172.22.22.250;
option subnet-mask 255.255.255.0;
option broadcast-address 172.22.22.255;
option routers 172.22.22.1;
}
/etc/default/isc-dhcp-server
sudo nano /etc/default/isc-dhcp-server
INTERFACES="eth1"
sudo service isc-dhcp-server stop
sudo service isc-dhcp-server start
ไม่มีความคิดเห็น:
แสดงความคิดเห็น