COLO.in.th > คลังความรู้ > ความรู้เกี่ยวกับ Linux > ติดตั้ง Gateway Server สำหรับ Centos (เบื้องต้น)


ติดตั้ง Gateway Server สำหรับ Centos (เบื้องต้น)




สำหรับเครื่องที่ติดตั้ง Lan card 2 ใบ
1. ติดตั้ง CentOS สำหรับ Server
2. ตรวจสอบการ์ดแลนทั้งสองใบได้ถูกติดตั้งลง CentOS
3.ตั้งค่าให้ eth0 เป็นการ์ดที่เชื่อมต่อไปยัง internet (แบบ static)

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0c:29:d2:c2:75
IPADDR=192.168.1.10             #
BROADCAST=192.168.1.255 #
NETMASK=255.255.255.0      #  ชุดไอพีของวงแลนขาออก internet
NETWORK=192.168.1.0         # 
GATEWAY=192.168.1.1           #
DNS1=8.8.8.8 #
DNS2=8.8.4.4 #
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
 
4. ตั้งค่าให้ eth1 เป็นการ์ดสำหรับใช้เป็นวงแลนภายใน
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=static
HWADDR=00:0c:29:d2:c2:7f
IPADDR=192.168.10.1                #
BROADCAST=192.168.10.255 # ตั้งค่า ip ของวงภายใน
NETMASK=255.255.255.0         #
NETWORK=192.168.10.0          #
GATEWAY=192.168.1.10            # ใส่ ip ของ eth0 หรือ gateway ของขาออก internet
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
restart network
# /etc/init.d/network restart
ถ้ามี error ที่ eth1 ให้พิมพ์
# service NetworkManager stop 
# chkconfig NetworkManager off
# service network start
# chkconfig network on
 
5. ตั้งค่า Gateway
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=nat
GATEWAY=192.168.1.1  # internet Gateway ของแลนขาออก internet
 
6. ตั้งค่า dns
# vi /etc/resolv.conf
nameserver 8.8.8.8 # Primary DNS ของ internet ที่ใช้อยู่ เช่นของ tot, 3bb, true
nameserver 8.8.4.4 # Secondary DNS ของ internet ที่ใช้อยู่ เช่นของ tot, 3bb, true
 
7. ติดตั้ง และตั้งค่า DHCP server
ติดตั้ง
# yum install dhcp
ตั้งค่า DHCP server
# vi /etc/dhcp/dhcpd.conf
option domain-name    "topcomputer.co.th";
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
subnet 192.168.10.0 netmask 255.255.255.0 {
  range dynamic-bootp 192.168.10.10 192.168.10.200;
  option broadcast-address 192.168.10.255;
  option routers 192.168.10.1; }
 
8. ตั้งค่า NAT ด้วย IP Tables
ลบ firewall rules

# iptables -F
# iptables -t nat -F
# iptables -t mangle -F

ลบ chains

# iptables -X
# iptables -t nat -X
# iptables -t mangle -X
ตั้งค่า ip forwarding และ masquerading
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# iptables -A FORWARD -i eth1 -j ACCEPT
Packet forwarding
# echo 1 > /proc/sys/net/ipv4/ip_forward
# vi /etc/sysctl.conf
แก้ net.ipv4.ip_forward=1
เซพ iptables
# service iptables save
# service iptables restart
 
9. ทดสอบ
ต่อเครื่องลูกเข้ากับ server ต้องได้รับ ip จาก dhcp ในช่วง 192.168.10.10 192.168.10.200
ลองคำสั่ง
# ping 192.168.10.1
# ping google.com
มีการตอบสนองจาก server หรือไม่
ถ้ามีการตอบสนอง internet gateway server นั้น ติดตั้งเรียบร้อยแล้ว

credit :

http://howto-madkour.blogspot.com/2013/08/linuxcentos-gateway-server.html

http://www.topcomputer.co.th/article/ติดตั้ง-gateway-server-สำหรับ-centos-เบื้องต้น



บทความนี้มีประโยชน์กับคุณหรือไม่ ?

บันทึกสู่รายการโปรดของฉัน บันทึกสู่รายการโปรดของฉัน    พิมพ์หัวข้อนี้ พิมพ์หัวข้อนี้

Also Read
ติดตั้ง OpenVZ บน CentOS 6.0 64bit (ดูรายละเอียด: 1276)
Linux Firewall iptables (ดูรายละเอียด: 2799)
Command Line (Linux Part II) (ดูรายละเอียด: 5180)

Powered by WHMCompleteSolution

ภาษา: