ในขณะที่โฆษณาออนไลน์เป็นแหล่งรายได้หลักที่ช่วยให้เว็บไซต์โปรดของคุณรวมถึงเว็บไซต์นี้สร้างรายได้ แต่บางครั้งผู้คนก็ต้องการบล็อกด้วยเหตุผลต่างๆ เช่น เป็นข้อกังวลด้านประสิทธิภาพหรือความเป็นส่วนตัว คุณสามารถติดตั้งซอฟต์แวร์บล็อกในแต่ละอุปกรณ์ที่คุณเป็นเจ้าของได้ แต่วิธีที่มีประสิทธิภาพที่สุดคือการสร้างเซิร์ฟเวอร์โดยใช้ Pi-hole ที่กรองปริมาณการใช้งานเว็บทั้งหมดของคุณในระดับเครือข่ายท้องถิ่น
Pi-hole คือ Raspberry ตัวบล็อกโฆษณาแบบกว้างตามเครือข่าย Pi เราติดตั้งซอฟต์แวร์ลงใน Raspberry Pi ที่ใช้ Raspberry Pi OS เรียกใช้การติดตั้งสั้นๆ สคริปต์แล้วชี้เครื่องของเราไปยังที่อยู่ IP ของ Raspberry Pi สำหรับการบล็อกโฆษณาทันที เราสามารถ–และเราสนับสนุนอย่างยิ่ง–เพิ่มไซต์ที่คุณใช้บ่อย เช่น tomshardware.com ลงในรายการที่อนุญาตพิเศษ เพื่อให้คุณสามารถช่วยพวกเขาเปิดไฟได้
ในบทช่วยสอนนี้ เราจะเปลี่ยน Raspberry Pi สำรองให้เป็นเครื่องบล็อกโฆษณา ซึ่งซ่อนไว้อย่างปลอดภัย บนเครือข่ายของเรา เราใช้ Raspberry Pi 4 แต่ได้รับข้อกำหนดต่ำสำหรับ Pi-หลุมนี้เป็นโอกาสที่ดีที่จะรื้อฟื้น Raspberry Pi เก่าที่คุณซุ่มซ่อนอยู่ในลิ้นชัก
สำหรับโครงการนี้ คุณจะต้องการ
- Raspberry Pi ใดๆ ที่มีอีเทอร์เน็ต
- สายไฟและสายเคเบิลอีเทอร์เน็ตสำหรับ Raspberry Pi ของคุณ
- พีซีที่ใช้ Windows
การตั้งค่า Raspberry Pi ของคุณ
1. ดาวน์โหลดและติดตั้ง Raspberry Pi Imager จากเว็บไซต์ Raspberry Pi
2. ใส่การ์ด microSD สำรอง ลงในคอมพิวเตอร์ของคุณ โปรดทราบว่าการ์ดใบนี้จะถูกลบออก
3. เปิด Raspberry Pi Imager แล้วกด SHIFT + CTRL + X เพื่อเปิดเมนูการกำหนดค่าลับ
4. เลื่อนลงและคลิกเปิดใช้งาน SSH จากนั้น ตั้งรหัสผ่าน SSH ใหม่ คลิกบันทึกเมื่อเสร็จแล้ว
5. ภายใต้ระบบปฏิบัติการ เลือก Raspberry Pi OS (32 บิต)
6. ใต้ที่เก็บข้อมูล คลิกที่ปุ่มและ เลือกการ์ด microSD ตรวจสอบอีกครั้งว่าคุณมีไดรฟ์ที่ถูกต้องก่อนดำเนินการต่อ
7. คลิกที่เขียน เพื่อดาวน์โหลดและเขียน Raspberry Pi OS ลงในการ์ด microSD เมื่อเสร็จแล้วให้นำการ์ดออกจากคอมพิวเตอร์ของคุณ
8. ใส่การ์ด microSD ของ Raspberry Pi OS ลงใน Raspberry Pi จากนั้นเชื่อมต่อ Raspberry Pi ของคุณกับเครือข่ายผ่านสายอีเทอร์เน็ต แล้วต่อไฟเพื่อบู๊ต Raspberry Pi
การติดตั้ง Pi-hole Over SSH
SSH การเชื่อมต่อที่ปลอดภัยกับ Raspberry Pi เป็นวิธีที่ดีที่สุด ติดตั้งและตั้งค่า Pi-hole เราสามารถใช้ไคลเอ็นต์ SSH เพื่อเชื่อมต่อได้ สำหรับ Windows คือ PuTTY และ Mac ผู้ใช้ Linux สามารถเชื่อมต่อโดยตรงผ่านเทอร์มินัล ด้วย SSH เราสามารถติดตั้งซอฟต์แวร์และดูแล Raspberry Pi ได้เหมือนกับว่าเรานั่งอยู่ข้างหน้ามัน
1. ผู้ใช้ Windows ดาวน์โหลดและ ติดตั้ง PuTTY ผู้ใช้ Linux และ Mac สามารถเปิดเทอร์มินัลได้โดยตรง
2. ผ่าน PuTTY ป้อนชื่อโฮสต์เป็น raspberrypi.local (ในบางเครือข่าย นี่เป็นเพียง raspberrypi ที่ไม่มี.local) แล้วคลิกเปิด
3. ป้อนชื่อผู้ใช้ของคุณ และ รหัสผ่าน เมื่อได้รับแจ้ง โปรดทราบว่าสิ่งเหล่านี้จะไม่ถูกพิมพ์ไปที่หน้าจอเพื่อความปลอดภัย
4. อัปเดตที่เก็บซอฟต์แวร์ของคุณ แล้วดาวน์โหลดการอัปเดตล่าสุดสำหรับ Raspberry Pi ของคุณ
$ sudo apt update
$ sudo apt อัปเกรด-y
5. ติดตั้ง Pi-hole โดยใช้สคริปต์การติดตั้งบรรทัดเดียวนี้ คำสั่งนี้จะดาวน์โหลดสคริปต์แล้วเรียกใช้โปรแกรมติดตั้งในเทอร์มินัล
$ curl-sSL https://install.pi-hole.net | ทุบตี
6. ตัวติดตั้ง Pi-hole จะเริ่มต้นด้วยการอัปเดตซอฟต์แวร์ที่มี จากนั้นวิซาร์ดการติดตั้งตามเมนูจะเริ่มต้นขึ้น กด Enter เพื่อดำเนินการติดตั้ง
7. เลือก eth0 เป็นอินเทอร์เฟซ เพื่อใช้กับ Pi-hole กด Tab เพื่อย้ายไฮไลท์สีแดงไปที่ Ok จากนั้นกด Enter นี่คือพอร์ต Gigabit Ethernet ของเราซึ่งจะให้การเชื่อมต่อที่ดีที่สุด
8. เลือกผู้ให้บริการ DNS ต้นทางของคุณ เราเลือก Google แต่มีอีกหลายคนให้เลือก กด Tab แล้วกด Enter
9. ยอมรับรายการเริ่มต้นของไซต์ที่ถูกบล็อก โดยกดแท็บและป้อน
10. ยอมรับโปรโตคอล IPv4 และ IPv6 เริ่มต้น โดยกดแท็บและป้อน
11. ยอมรับการตั้งค่าเครือข่ายปัจจุบัน และตั้งค่าเป็นแบบคงที่ จดบันทึกรายละเอียดตามที่เราต้องการในภายหลัง
12. Install the web admin interface by pressing tab and enter.
13. Install the lightppd web server used to serve the web admin pages by pressing tab and enter.
14. Accept the default log options.
15. Accept the default privacy mode by pressing tab and enter.
The installation is complete and the final page recaps the IP address of the Pi-hole device and provides an admin webpage login password.
16. Change the web admin password in the terminal using the following command. You will be prompted to type in the password twice.
$ pihole-a-p
Setting Network Connections for Pi-hole
With our Raspberry Pi running Pi-hole setup and running we now need to point our devices to it so that Pi-hole’s DNS servers can block unwanted advertisements. Here we are manually setting up a wired network connection with Windows 10. The steps will be similar for Wi-Fi.
1. Right click on the Windows logo and select Network Connections.
2. Click on Properties.
3. Click on Edit to update the network configuration.
4. Edit your IP address to your desired address. We chose to stick with what the router’s DHCP server issued. Set the Subnet prefix length to 24. The Gateway is the IP address of the router, in our case 192.168.0.1. Preferred DNS is our Pi-hole DNS server, 192.168.0.24. The Alternative DNS is used if our Pi-hole device goes offline, in this case it is Google’s DNS server. Click Save to write the changes and restart the network interface.
How to Whitelist a Site in Pi-Hole
Considering that many content sites, including ours, rely on advertising for a significant portion of their revenue, it makes sense to whitelist those you wish to support so they can serve you ads. Pi-hole has a whitelist menu where we can add specific domains and subdomains which will be added to Pi-hole’s lists.
1. Open a web browser to the IP address of your Raspberry Pi, and type/admin. For our setup we went to http://192.168.0.34/admin/
2. Log in to your Pi-Hole by entering the username and password. We earlier changed the admin login password.
3. From the dashboard click Whitelist.
4. Under Domain, add the URL of the site that you wish to whitelist, then click Add to Whitelist. This site will now be able to serve adverts.
Domains can be enabled/disabled in the whitelist by clicking on the button under Status. Whitelisted domains can be deleted by clicking on the trashcan icon.
5. Click logout to return to the default admin page.
There you have it, your browser tabs are free of adverts and your browsing just got a lot faster, all thanks to that spare Raspberry Pi that was lurking in your drawer.