Skip to content

Instantly share code, notes, and snippets.

@willywotz
Last active September 15, 2020 06:23
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/7c11bc87081a33d1b5cc5abed0fc3bef to your computer and use it in GitHub Desktop.
Save willywotz/7c11bc87081a33d1b5cc5abed0fc3bef to your computer and use it in GitHub Desktop.
  • แก้ไขรหัสผ่านห้องรูท sudo passwd
  • เข้าห้องรูท sudo su
  • อัพเดตระบบ apt-get update
  • ดูการ์ดแลนทั้งหมด ifconfig -a
  • แก้ไขการ์ดแลนตัวที่ 2 ifconfig eth1 dstaddr 10.0.2.1 netmask 255.255.255.0
  • เปิดใช้งานการ์ดแลนตัวที่ 2 ifup eth1
  • ติดตั้งโปรแกรมแจก ip apt-get install isc-dhcp-server -y
  • แก้ไขโปรแกรมแจก ip nano /etc/dhcp/dhcpd.conf
subnet 10.0.2.0 netmask 255.255.255.0 {
  range 10.0.2.2 10.0.2.254;
  option routers 10.0.2.1;
  option domain-name-servers 8.8.8.8;
}
  • แก้ไขการ์ดแลนที่ใช้แจก ip nano /etc/default/isc-dhcp-server เพิ่มเป็น INTERFACES="eth1"
  • เปิดโปรแกรมแจก ip service isc-dhcp-server start
  • sysctl -w net.ipv4.ip_forward=1
  • ทำให้เครื่องที่ได้รับ ip ออกเน็ตได้ nano /etc/rc.local เพิ่ม iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE ก่อน exit 0
  • สั้งให้การตั้งค่าเส้นทาง network ทำงาน /etc/rc.local
  • ติดตั้งโปรแกรมช่วยบล๊อก apt-get install squid3 -y
  • แก้ไขโปรแกรมช่วยบล๊อก nano /etc/squid3/squid.conf
cache_store_log stdio:/var/log/squid3/store.log
cache_store_log daemon:/var/log/squid3/store.log

acl localnet src 10.0.2.0/24

http_access allow localnet

http_port 3128 intercept
  • ดูพื้นที่ hdd df -BM --total
  • แก้ไขขนาดการแคชบนดิสของโปรแกรมช่วยบล๊อก nano /etc/squid3/squid.conf แก้เป็น cache_dir ufs /var/spool/squid3 8097 16 256 เลข 8097 คือเลขพื้นที่ 80% ของ hdd ในกรณีที่ตั้งการแคชอย่างเต็มพิกัด
  • ดูขนาดแรม free -m
  • แก้ไขขนาดการแคชบนแรมของโปรแกรมช่วยบล๊อก nano /etc/squid3/squid.conf แก้เป็น cache_mem 682 MB เลข 682 คือเลข 1 ใน 3 ของ free ram (+-buffer) บวกกับ 10 MB ต่อขนาดการแคชบนดิส 1 GB
  • เพิ่มเส้นทางเข้าโปรแกรมช่วยบล๊อก nano /etc/rc.local เพิ่ม iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128 ก่อน exit 0
  • รีเซ็ตการตั้งค่าเส้นทาง network iptables -t nat -F
  • สั้งให้การตั้งค่าเส้นทาง network ทำงาน /etc/rc.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment