Showing posts with label DianseH - Linux Script. Show all posts
Showing posts with label DianseH - Linux Script. Show all posts

Monday, August 25, 2008

How To Integrate HTB-tools with Squid + ZPH (ver. 2)

This section about howto integrate squid + zph + htb-tools on my slackware 12.0. What different ver.1 and ver.2 ?
User can't using q_show to monitoring cache hit from squid in ver.1
User will be seeing Cache_HIT as additional class in q_show result for ver.2

Here the steps:

Assumption : User already have squid + zph + htb-tools installed.
squid-2.7Stable4 (zph_local 0x30 included)
HTB-tools-0.3.0a

1. I've replace original /sbin/q_parser with my new q_parser
2. Inserting several lines inside eth1-qos.conf (interface for LAN)
#---this lines put on the top -----
class Cache_HIT {
bandwidth 10000;
limit 10000;
burst 2;
priority 1;
};

# --- LAN Rules ---
# make your own rule


3. Generate your config with q_parser and apply on system
root@dianseh# q_parser eth1 100000 100000 /etc/htb/eth1-qos.conf > /usr/local/bin/eth1-qos.sh
root@dianseh# chmod +x /usr/local/bin/eth1-qos.sh
root@dianseh# /usr/local/bin/eth1-qos.sh

or

root@dianseh# /sbin/htb eth1 stop
root@dianseh# /sbin/htb eth1 start

5. Monitoring q_show
root@dianseh# /sbin/htb eth1 stats



the picture shown users who get HIT from squid have 6mbps of 10mbps guarantee.


Note :
Tested on Slackware 12.0 and working properly. What about you?

references :
1.http://www.vivaolinux.com.br/perguntas/
2.http://google.com

Thanks to Mr'Ipung who asked me todo.


Thursday, August 14, 2008

How To Integrate HTB-tools with Squid + ZPH (ver. 1)

I'm goin to tell you my search result @ google that i've implemented on my friend's server. It begins when my friend has asked me to integrate Squid + zph with HTB-tools in same machine.
"3 In One, no need many servers for warnet laaaah" as he said.

This time it's about Linux Ubuntu not Slackware as usual.

Illustration :

1. Internet <> Linux <> Lan


2. Linux as gateway, Proxy and Shaper server.
O/s : Ubuntu
Proxy : squid-2.7.STABLE4 with ZPH included
Limiter : HTB-Tools
Kernel : 2.6.21

3. HTB has been installed on System.

My experience begins at HTB with Squid+zph integration.

Steps :

1. Extract and Install Squid 2.7. How to install for squid 2.6 can found at here. Edit squid.conf and insert these line below.
zph_mode tos
zph_local 0x30

2. Installing HTB-tools and make your own rule to shape LAN's ip.

3. Generate htb config eg. eth1-qos.conf
root@dianseh# q_parser eth1 100000 100000 /etc/htb/eth1-qos.conf > /usr/local/bin/eth1-qos.sh
root@dianseh# chmod +x /usr/local/bin/eth1-qos.sh


4. Edit eth1-qos.sh
----find this line---
tc qdisc add dev eth0 parent 1;0x10 handle 0x10: pfifo limit 5
----insert these line----
tc class add dev eth0 parent 1;1 classid 1;0x15 htb rate 10Mbit
tc filter add dev eth0 parent 1;0 protocol ip prio 1 u32 match ip protocol 0x6 0xff match ip tos 0x30 0xff flowid 1;15


5. Excute eth1-qos.sh to starting.
6. Put it into startup script
7. Done.

Please tell me if any additional information or missconfiguration.


Good Luck



References :

1. squid + zph
2. http://zph.bratcheda.org/eg_tos_marking.html

Saturday, August 9, 2008

How To Limit New Incoming Connections With Iptables (Slackware)

Linux box with iptables installed can apply this scenario.

Someday i have to add rule on my iptables to controlling any new incoming connections on my Slackware. This is needed because my server starting recived many unused incoming connection from outside. Flooding on my telnet port every minutes made fullfill my log. I need a smart way to manage it. Search from Google for a while and get some resources that can resolve my situation.

Let me share for you all.

Tested on Slackware 12.0, iptables v1.3.8 and work properly.

That is:

1. Ilustration :
We need rule to manage only 2 new connections allowed in 60 second entering our Linux system from same source address for some security reasons.

2. Code :
# iptables -I INPUT -p tcp --dport 23 -i eth1 -m state --state NEW -m recent --set
# iptables -I INPUT -p tcp --dport 23 -i eth1 -m state --state NEW -m recent --update \
--seconds 60 --hitcount 2 -j DROP


3. Brief Explanation :
-
First line match for any new connection to port 23 from some source addresses and the rule will adding that source address into entry list Default variable.

- Line two will make linux box not available for new incoming connection on port 23 from source address who have make 2 new connections on port 23 in last 60seconds.

note :
Need more little work for some advanced rules. These iptables rule effective when applied to TCP Protocols. Other protocols has not been tested yet. I haven't found the right and effective method to test those rules other than tcp. When you did, please notify me about the results.

Good Luck, Selamat mencoba

Referensi ; google.com, iptables howto, debian firewall howto, etc
Thanks to Indonesian's Linuxer Comunity. Bravo!

Script Auto SCP/SFTP On Linux

We need a script that can send username / password in our Linux Box to transfer files through SFTP or SCP.

Requirement
1. OpenSSH
2. Expect

Illustrations :

We want to get "passwd" file on Server-A (192.168.1.1) and saved to /home/dianseh/passwd-Server-A on Server-B (192.168.1.2).

Server-B 192.168.1.2 ingin mengambil file di Server-A 192.168.1.1.
File Yang akan diambil dan disimpan adalah "passwd" dan di simpan pada direktori /home/dianseh pada server-B dengan nama file "passwd-Server-A"

The script is :

---- Script Start -----

#!/usr/bin/expect --
#spawn sftp dianseh@192.168.1.1:/etc/passwd /home/dianseh/passwd-Server-A
spawn scp dianseh@
192.168.1.1:/etc/passwd /home/dianseh/passwd-Server-A
expect "dianseh@
192.168.1.1's password:"
send "passwordnya\r"
expect "%$"


---- Script End -----

Note :
Let me know if it's working.

Good Luck