วิธีการ คือ ให้เรากำหนด ระบบ iptables เพิ่มเต็มให้มัน ในส่วนของกรณี
ให้มัน ACCEPT IP dns ที่เราต้องการจะให้มันผ่าน ส่วนของ Squid ไปเลยครับ
โดย อาจจะเพิ่มเต็มว่า
กรณี เดิมคือ
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
เราจะต้องรู้เป้าหมายเว็บของเราก่อนว่า มี ip เป็นอะไรนะครับ จากนั้น จัดการตรวจสอบว่า
nslookup hostname เช่น
nslookup www.sanook.com มันจะออกมาเป็น ip ให้ทราบครับผม
เช่น ตัวอย่าง
nslookup www.sanook.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: www.sanook.com
Address: 203.107.165.221
เรารู้แล้วว่ามี ip 203.107.165.221
เราก็จัดการนำไปใส่ เอาไว้ ว่า
iptables -t nat -I PREROUTING -d 203.107.165.221 -j ACCEPT
ระบบนี้มันจะ บอกว่า สำหรับเว้บ www.sanook.com ไม่ต้องให้มีการเก็บ Cache ครับ
สามารถ นำไป ขยาย ความเป็น Script แบบง่าย ๆได้ดังนี้
พิมพ์ ว่า
nano /root/bypass_squid.sh
แล้ว พิมพ์ เข้าไปดังด้านล่างนี้ ว่า
#!/bin/bash
# Genarate PF-internet
ip_bypass=nslookup $1 | grep Addre | grep -v "#53" | cut -d " " -f 2
iptables -t nat -I PREROUTING -d $ip_bypass -j ACCEPT
จากนั้น ทำการ Save ครับ แล้วจัดการ
chmod 755 /root/bypass_squid.sh
แล้ว ทดสอบ ก็ พิมพ์ว่า
/root/bypass_squid.sh www.teenee.com
ดูครับมันจะจัดการใส่ เข้าไปให้ เอง แต่ในกรณีมีหลาย ๆ ip ละทำงั้ยเช่น
nslookup www.google.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
www.google.com canonical name = www.l.google.com.
Name: www.l.google.com
Address: 64.233.181.147
Name: www.l.google.com
Address: 64.233.181.106
Name: www.l.google.com
Address: 64.233.181.105
Name: www.l.google.com
Address: 64.233.181.104
Name: www.l.google.com
Address: 64.233.181.103
Name: www.l.google.com
Address: 64.233.181.99
มีตั้ง 6 ตัว ทำงั้ยดีทีนี้
อาจจกทำดังต่อไปนี้ครับ
nslookup www.google.com | grep Add | grep -v "#53" > /root/C_bypass
ลอง
cat /root/C_bypass
Address: 64.233.181.99
Address: 64.233.181.147
Address: 64.233.181.106
Address: 64.233.181.105
Address: 64.233.181.104
Address: 64.233.181.103
จะมีข้อมูลดังนี้ จัดการต่อว่า
จัดการต่อว่า
Count=wc -l /root/C_bypass | awk '{print$1}'
for ((zz=1; zz<=$Count; zz++)); do
Count=`cat /root/C_bypass | cut -d " " -f 2 | head -n 1`
iptables -t nat -I PREROUTING -d $Count -j ACCEPT
sed -i '/'$Count'/d' /root/C_bypass
done
ก็จะสามารถใช้งานแบบง่ายๆ ได้ครบทุกตัวแล้วครับ แล้วครับ
จัดการสร้างไฟล์ว่า
nano /root/gen_bypass.sh
ใส่ ข้อมูลไปว่า
#!/bin/bash
# Genarate By PF-internet
nslookup $1 | grep Add | grep -v "#53" > /root/C_bypass
Count=wc -l /root/C_bypass | awk '{print$1}'
for ((zz=1; zz<=$Count; zz++)); do
Count=`cat /root/C_bypass | cut -d " " -f 2 | head -n 1`
iptables -t nat -I PREROUTING -d $Count -j ACCEPT
sed -i '/'$Count'/d' /root/C_bypass
done
ทำการ Save และ ออก
จากนั้น
chmod 755 /root/gen_bypass.sh
ทดสอบ
/root/gen_bypass.sh www.google.com
ครับผม น่าจะช่วยให้ท่านทำได้ บ้างนะครับ
Credit : webddgame http://www.3poe.com
ไม่มีความคิดเห็น:
แสดงความคิดเห็น