Posts with the name or tag of CentOS;

by emran

Get your ip

10:41 pm in CentOS, Debian, Fedora by emran

#!/bin/bash
# get ip
/sbin/ifconfig $1 | grep inet | awk ‘{print $2}’ | sed ‘s/^addr://g’

To get your Internet address if you are behind a NAT:

## The -n option retrieves the Internet IP address

## if you are behind a NAT

if [ "$1" = "-n" ]

then ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)

else if=$1 ## specify which interface, e.g. eth0, fxp0

system=$(uname)

case $system in FreeBSD)

sep=”inet “ ;;

Linux) sep=”addr:” ;;

esac temp=$(ifconfig $if)

temp=${temp#*”$sep”}

 ip=${temp%% *}

fi

printf “%s\n” “$ip”

### CFAJ ###

by emran

Squid restrict file Extensions using time slot

9:52 pm in CentOS, Linux by emran

Create two ACL one for Time slot and one for file extensions.

#vi /etc/squid/squid.conf

Add the followings

acl filetime time 09:00-13:00 #(filetime is ACL name)

acl blockfile url_regex -i .iso$ .exe$ .ini$ .gz$ .tar$ .zip$ .tgz .bz2$ .bin$ .rar$ .bin$ #(“blockfile” is ACL for file types which need to be restricted)

http_access deny blockfile filetime (# Now deny the ACL blockfile with filetime )

#/etc/init.d/squid reload

by emran

Adding custom route on Debian network script

9:48 pm in CentOS, Debian, Fedora, FreeBSD, Linux by emran

Add the following line on /etc/network/interfaces

up route add -net 172.22.0.0 netmask 255.255.254.0 gw 192.168.15.101 dev eth0 (The connected Hardware interface.)

Now restart the network service by

#/etc/init.d/networking restart

by emran

Setting Auto Reply Mail on Linux

9:44 pm in CentOS, Debian, Fedora, Linux by emran

Enable Auto-Reply

Go to users home folder (here we want to create auto-reply for “user” account)

cd /home/user

create .forward file

vi .forward (add the following line)

|/usr/bin/procmail

create .procmailrc

vi .procmailrc (add the following lines)

SHELL=/bin/sh :0 h c * !^FROM_DAEMON * !^X-Loop: user@example.com | (formail -r -I”Precedence:junk” \ -A”X-Loop: user@example.com ” ; \ cat $HOME/message; \ ) | $SENDMAIL -oi -t :0

create a file message-

vi message

hi, I will be leave on ………… (here you add your message which will be sent to the sender during your vacation)

Disable Auto-Reply

Go to users home folder (here we want to remove auto-reply settings of “user” account)

cd /home/user

mv .forward forward

mv .procmailrc procmailrc

by emran

IPTables firewall in VoIP Server

9:52 pm in CentOS, Fedora, OpenSIPS by emran

Please put this following code in iptables script:

:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT – [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp –dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 631 -j ACCEPT

-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp -s 3.16.1.93 –sport 53 -d 0/0 -j ACCEPT

-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 7968 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 50000:59999 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 20000:20999 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 30000:30999 -j ACCEPT

-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 5060 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 5061 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 1720 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 1719 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 1718 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 5060 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 5061 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 8000:20000 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 50000:59999 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 20000:20999 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 30000:30999 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
## ftp
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT

by emran

How to install yum from source?

9:48 pm in CentOS, Fedora by emran

download the .tar source and set it up..

read the readme file in it..Pretty easy..

As root,
cd ~
mkdir setups
cd setups
wget http://linux.duke.edu/projects/yum/download/2.0/yum-2.0.7.tar.gz
tar -xvzf yum-2.0.7.tar.gz
cd yum-2.0.7
./configure
make
make install