Thursday, December 30, 2010

OpenVPN & SSH Tunnel

yum install rpm-build autoconf.noarch zlib-devel pam-devel openssl-devel


download dan install lzo dan openvpn

wget http://repo.securityteam.us/repository/redhat/el4/i386/RPMS/openvpn-2.0.9-1.i386.rpm
http://204.74.208.18/lzo-devel-1.08-4.2.el5.rf.i386.rpm http://204.74.208.18/lzo-1.08-4.rf.src.rpm http://204.74.208.18/lzo-1.08-4.2.el5.rf.i386.rpm

Install lzo dan openvpn dengan perintah sbb:
rpm –ivh lzo*
rpm –ivh openvpn-2.0.9-1.i386.rpm

Copy easy rsa ke directory openvpn
cp -r /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/

Membuat certificate
. ./vars Perhatikan, .(spasi).vars
./clean-all #Akan mengosongkan direktori keys/
./build-ca
Kemudian input data sesuai dengan konfigurasi kita, tekan enter untuk variabel yang sebelumnya sudah kita tentukan di file vars, dan sesuaikan Common Name dengan hostname server kita;
Buat server key
./build-key-server ovpnserver
./build-dh

Copy semua file keys dan certificate ke /etc/openvpn
cp keys/* /etc/openvpn

lalu masuk ke direrctory openvpn
cd /etc/openvpn

Buat file configurasi server
vi server.conf

plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so login
client-cert-not-required
username-as-common-name
port 1194
proto udp
dev tun
ca ca.crt
cert ovpnserver.crt
key ovpnserver.key
dh dh1024.pem
server 10.14.0.0 255.255.255.0
ifconfig-pool-persist ipp2.txt
push "dhcp-option DNS 4.2.2.1"
push "dhcp-option DNS 4.2.2.2"
client-to-client
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status2.log
log openvpn2.log
verb 3

lalu simpan file konfigurasi
tekan esc lalu :wq!

Jalankan openvpn dengan cli sbb
service openvpn start

Buat konfigurasi file client

client
dev tun
proto tcp
remote 74.xx.xx.xx 1194
remote-random
redirect-gateway def1
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
auth-user-pass
comp-lzo
verb 3


Mefungsikan server sebagai gateway internet
1. enable port forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
2. mengaktifkan iptables
buat file dengan nama iptables-script.sh

CLI sbb :
vi iptables-script.sh
IPT=/sbin/iptables
LANIFACE=venet0 --- jika dedicated server ganti dengan eth0/eth1 sesuao dengan interfacenya
VPNIFACE=tun0
VPN=10.15.0.0/24
$IPT -A INPUT -i $VPNIFACE -j ACCEPT
$IPT -A FORWARD -i $VPNIFACE -j ACCEPT
$IPT -t nat -A POSTROUTING -s $VPN -o $LANIFACE -j SNAT --to 204.xx.xx.xx

Setelah scrip siap jalankan script denga perintah sh iptables-script.sh
setelah itu install ptunnel pada server

dengan cara sebagai berikut
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
setelah download selesai ketik kan perintah tersebut
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
setelah compile selesai ketik kan
yum install ptunnel
tunggu sampe instal selesai dan update openssh nya dengan cara sebagai berikut
wget http://layer1.rack911.com/openssh/rhel5/x86_64/openssh-5.2p1-1.x86_64.rpm
wget http://layer1.rack911.com/openssh/rhel5/x86_64/openssh-clients-5.2p1-1.x86_64.rpm
wget http://layer1.rack911.com/openssh/rhel5/x86_64/openssh-server-5.2p1-1.x86_64.rpm
rpm -Uvh openssh*
setelah itu edite config sshd config nya
dengan cara vi /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd(8) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation no

# Lifetime and size of ephemeral version 1 server key
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 600
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
MaxSessions 40
#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

UsePAM yes

No comments:

Post a Comment

My Mine