วิธีทำ NAT แชร์เน็ตแบบรีบๆ บน Ubuntu

mrgill   | January 24, 2011   |   1,510 Views

ตามนี้เลยครับ สำหรับใครที่ต้องการแชร์เน็ตแบบทันใจ

โดยให้ eth0 เป็นขาที่ต่อเน็ต และขา eth1 เป็นขา local ที่ต้องการจะแชร์เน็ต มาดูวิธีกัน

กำหนด IP ของ eth1 ของเครื่องแม่ที่ต้องแชร์เน็ตให้เป็น 192.168.1.1/24

กำหนด IP เครื่อง Client ที่ต้องการจะแชร์เน็ตให้เป็น 192.168.1.xxx/24 ในที่นี้ผมกำหนดเป็น 192.168.1.10/24 และชี้ Gateway มาที่เครื่อง 192.168.1.1 ส่วน DNS ก็ชี้ไปที่ไหนก็ได้ครับ ผมขอชี้ไปที่ 8.8.8.8 ของ Google ละกัน

มาถึงส่วน Script กันบ้าง

สร้างไฟล์ nat.sh จากนั้น Copy Script ด้านล้างไปวางแล้ว Save

#!/bin/bash #Express NAT Shell Script echo "1" > /proc/sys/net/ipv4/ip_forward iptables -P FORWARD DROP iptables -A POSTROUTING -t nat -s 192.168.1.0/24 -o eth0 -j MASQUERADE iptables -A FORWARD -d 192.168.1.0/24 -j ACCEPT iptables -A FORWARD -s 192.168.1.0/24 -j ACCEPT iptables -A FORWARD -j DROP

จากนั้นกำหนดสิทธิ์ให้สามารถรันได้โดย

sudo chmod +x nat.sh

แล้วก็รันกันได้เลย

sudo ./nat.sh

ทดลองเล่นเน็ตจากเครื่อง Client กันได้เลยจ้า

Comments

Category : Daily command,Daily tips,How to,Internet,Linux,Security,Ubuntu

Tags: iptables, nat

Related Posts

แนะนำเว็บไซต์สำหรับคนชอบเล่นเกมส์บน Ubuntu Factory Reset บน Fortigate 100A ทำไง

1 Comment Leave a Comment

  • 1. Video Game Design  |  February 22, 2011 at 7:32 PM

    กำลังหาอยู่เลยครับ กำลังทำโปรเจคส่งอาจารย์

Leave a Comment

(required)

(required), (Hidden)

 

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

TrackBack URL  |  RSS feed for comments on this post.


Chat

Recent Entries

Random Posts

Social Network

Tag Cloud

Calendar

January 2011
S M T W T F S
« Nov   Feb »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Twitter: imrgill

RSS LinuxToday

RSS HowToForge

RSS UbuntuClub

RSS Blognone

RSS PowerWindowsBlog

Tag

Categories

Archives

Blogroll

Meta

Get Adobe Flash player