Selasa, 03 Januari 2012

Membuat Server Centos Menjadi Gateway dan Transparent Proxy dengan Squid

Dalam hal ini tersedia :

1. Server Linux Centos dengan 2 NIC
- eth0 : 192.168.200.200 terhubung ke internet melalui proxy (gateway 192.168.200.1)
- eth1 : 192.168.210.1 terhubung dengan client di ruangan
2. Proxy server menggunakan Squid
- setup awal squid dengan –> klik

Tujuan :

1. Komputer di dalam ruangan bisa melakukan koneksi ke jaringan luar akan tetapi komputer di jaringan luar tidak bisa masuk ke komputer yang ada di ruanga

Tahapan yang dilakukan yaitu :

1. Membuat Centos agar menjadi router, Disini disiapkan router ang bersifat Masquerading, maksudnya yaitu, semua komputer yang ada di ruangan (yang terhubung melalui gateway eth1) akan bisa melakukan koneksi ke luar melalui eth0 dan mengatas namakan eth0. Misalnya komputer di ruangan IPnya adalah 192.168.210.12 melakukan browsing ke server 192.168.220.5 (komputer di LAN lain yang bisa diakses melalui eth0), maka komputer server 192.168.220.5 akan membaca yang akses ke servernya adalah 192.168.200.200 bukannya 192.168.210.12. Atau dengan kata lain masquerading bermaksud membungkus alamat IP asli menjadi alamat IP yang Masquerading.Scrip yang disiapkan yaitu

# Hapus semua seting yang sudah ada.
iptables –flush
iptables –table nat –flush
iptables –delete-chain
iptables –table nat –delete-chain

# Set up IP FORWARDing and Masquerading
iptables –table nat –append POSTROUTING –out-interface eth0 -j MASQUERADE
iptables –append FORWARD –in-interface eth1 -j ACCEPT

# Aktifkan packet forwarding di kernel
echo 1 > /proc/sys/net/ipv4/ip_forward

# routing
route add -net 192.168210.0 netmask 255.255.255.0 gw 192.168.200.1 dev eth1

2. Setup squid agar support transparent proxyYang dimaksud transparent proxy yaitu secara mudahnya adalah agar browsing di browser tidak usah melakukan seting proxy (tanpa proxy atau default port 80).Di Squid bisa dicek di data berikut :

# TAG: http_port
# Usage: port [options]
# hostname:port [options]
# 1.2.3.4:port [options]
#
# The socket addresses where Squid will listen for HTTP client
# requests. You may specify multiple socket addresses.
# There are three forms: port alone, hostname with port, and
# IP address with port. If you specify a hostname or IP
# address, Squid binds the socket to that specific
# address. This replaces the old ‘tcp_incoming_address’
# option. Most likely, you do not need to bind to a specific
# address, so you can use the port number alone.
#
# The default port number is 3128.
#
# If you are running Squid in accelerator mode, you
# probably want to listen on port 80 also, or instead.
#
# The -a command line option will override the *first* port
# number listed here. That option will NOT override an IP
# address, however.
#
# You may specify multiple socket addresses on multiple lines.
#
# options are:
# transparent Support for transparent proxies
# vhost Accelerator using Host directive
# vport Accelerator with IP virtual host support
# vport= As above, but uses specified port number
# rather than the http_port number.
# defaultsite= Main web site name for accelerators.
# urlgroup= Default urlgroup to mark requests
# with (see also acl urlgroup and
# url_rewrite_program)
# protocol= Protocol to reconstruct accelerated
# requests with. Defaults to http.
# no-connection-auth
# Prevent forwarding of Microsoft
# connection oriented authentication
# (NTLM, Negotiate and Kerberos)

# tproxy Support Linux TPROXY for spoofing
# outgoing connections using the client
# IP address.
#
# If you run Squid on a dual-homed machine with an internal
# and an external interface we recommend you to specify the
# internal address:port in http_port. This way Squid will only be
# visible on the internal address.
#
# Squid normally listens to port 3128
http_port 3128 transparent

Disini kita set proxy aktif di port 3128 dan transparent.
Langkah yang disiapkan yaitu :
1. Lakukan redirect akses yang bertujuan di port 80 ke port 3128 (port proxy)

iptables –table nat –append PREROUTING -i eth1 -p tcp –dport 80 -j REDIRECT –to-port 3128

printah ini bermaksud melakukan aturan dalam iptable agar paket tcp yang tujuannya port 80 diarahkan ke port 3128 (proxy server). Perintah ini bisa di tambahkan dalam scrip di pembuatan gateway diatas.

2. Uji coba proxy
2.1. Ujicoba dengan browser

Dari browser di komputer client dengan isian proxy di kosongkan (tanpa proxy) lakukan browsing ke www.sampangan.com

2.2. Apabila gagal, coba lakukan pengujian dengan telnet, “telnet 192.168.210.1 80″

telnet 192.168.210.1 80
Trying 192.168.210.1…
Connected to 192.168.210.1.
Escape character is ‘^]’.

kemudian tuliskan alamat website yang akan dibuka, misalnya www.sampangan.com
elinks http://www.sampangan.com

maka berikutnya akan muncul isi text dari www.sampangan.com

2.3. Apabila 2.2 berhasil membuka alamat website dengan port 80 akan tetapi 2.1 gagal, maka perlu diperhatikan sebagai berikut :
- Alamat gateway komputer client harus ke 192.168.210.1 karena dia gateway clien ya..
- Alamat DNS server harus betul dan bisa berfungsi, apabila kosong/ tidak berfungsi maka tidak akan bisa browsing bukannya di #vi /etc/resolf.conf
masukkan ip NDS nya

Tidak ada komentar:

Posting Komentar