Skip to content

Instantly share code, notes, and snippets.

@willywotz
Last active September 10, 2020 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willywotz/426336aa9d68e6e904b5bac8754c0de4 to your computer and use it in GitHub Desktop.
Save willywotz/426336aa9d68e6e904b5bac8754c0de4 to your computer and use it in GitHub Desktop.
  • เข้าห้อง root sudo su
  • เตรียมพร้อมเครื่องแม่ข่าย apt-get update; apt-get upgrade -y
  • ตรวจสอบเน็ตเวิร์ก ifconfig -a -s ควรขึ้น Iface 3 ตัวเป็นอย่างน้อย
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
em1        1500 0     41263      0      8 0         12963      0      0      0 BMRU
em2        1500 0       541      0      0 0            51      0      0      0 BMRU
lo        65536 0       102      0      0 0           102      0      0      0 LRU
  • ถ้าขึ้นเพียงหนึ่่งตัวให้ทำการตรวจสอบการ์ดเน็ตเวิร์ก
  • สำหรับ eth0 และ eth1 หากเป็นตัวอักษรอื่นให้ยึดตามตัวนั้น เช่น eth0 ขึ้นเป็น enp0s3 ให้ใช้ enp0s3 แทน eth0
  • ตั้งค่าวงเน็ตเวิร์กสำหรับกระจายที่อยู่ ip nano /etc/network/interfaces
# 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 static
  address 192.168.0.202
  netmask 255.255.255.0
  network 192.168.0.0
  broadcast 192.168.0.255
  gateway 192.168.0.1
  # dns-* options are implemented by the resolvconf package, if installed
  dns-nameservers 192.168.0.1
  dns-search rc.local

auto eth1
iface eth1 inet static
  address 10.9.0.1/20
  • สำหรับเลข ip address ของ eth1 ขึ้นอยู่กับที่จะใช้เป็นวงเน็ตเวิร์กที่จะกระจาย
  • สำหรับ / หลังตัวเลข ip address ขึ้นอยู่กับ netmask
    • 255.255.255.0 จะเป็น /24
    • 255.255.240.0 จะเป็น /20
  • ตั้งค่าการส่งต่อ ip nano /etc/sysctl.conf หา # net.ipv4.ip_forward=1 ลบ # ข้างหน้าออก
  • เปิดการส่งต่อ ip echo 1 > /proc/sys/net/ipv4/ip_forward
  • รีสตาร์เน็ตเวิร์ก service networking restart
  • ตรวจสอบสถาณะเน็ตเวิร์ก service networking status หากขึ้น networking start/running ถือว่าได้
  • ลงโปรแกรมสำหรับกระจาย ip apt-get install isc-dhcp-server
  • ตั้งค่าการกระจาย ip nano /etc/dhcp/dhcpd.conf
  • หาและทำการลบ # ข้างหน้าออก
#default-lease-time 600;
#max-lease-time 7200;
  • เพิ่มที่ท้ายสุด
subnet 10.9.0.0 netmask 255.255.240.0 {
  range 10.9.0.20  10.9.15.254;
  option routers 10.9.0.1;
  option domain-name-servers 8.8.8.8;
}
  • แก้ไข interfaces ที่ใช้งาน dhcp server nano /etc/default/isc-dhcp-server หา INTERFACES="" เพิ่ม INTERFACES="eth1"
  • รีสตาร์ dhcp server service isc-dhcp-server restart
  • ตรวจสอบ dhcp server service isc-dhcp-server status หากขึ้น isc-dhcp-server start/running, process 2843 เป็นอันใช้ได้ *ไม่สนใจตัวเลขข้างหลัง
  • ให้ตรวจสอบเครื่องลูกข่ายว่าได้รับ ip หรือไม่
  • แก้ไขไฟล์เพื่อให้สามารถออกอินเตอร์เน็ต nano /etc/rc.local เพิ่ม iptables -t nat -A POSTROUTING -o em1 -j MASQUERADE ข้างบน exit 0
  • รันไฟล์ /etc/rc.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment