My Blog

contains PHP and other web related content. (Sometimes there are some off topic things - don't freak out!)

Posts Tagged ‘linux’

Block and Allow IP with iptables – simple script

Wednesday, November 25th, 2009

As most developers are lazy, I’m a huge fan of scripts. I’ve found myself lately having to add entries to iptables to block a single IP or a small subnet, so I made a quick script to make the job easier on myself.

Usage for both of these is of course really simple. Say 123.1.2.3 is the IP in question:

sudo ./blockip.sh 123.1.2.3
sudo ./allowip.sh 123.1.2.3

blockip.sh
Blocks the IP using iptables

1
2
3
4
5
6
7
#!/bin/bash
 
#blocking iptables
/sbin/iptables -A INPUT -s $1 -j DROP
 
#saving iptables
/sbin/iptables-save > /etc/sysconfig/iptables

allowip.sh
Removes the entry from iptables

1
2
3
4
5
6
7
#!/bin/bash
 
#allowing iptables
/sbin/iptables -D INPUT -s $1 -j DROP
 
#saving iptables
/sbin/iptables-save > /etc/sysconfig/iptables

Send email from server to gmail using postfix

Wednesday, October 7th, 2009

The other day I ran into this problem where postix insisted on delivering mail… as it was supposed to do! As it was configured! But this isn’t what I wanted. Let me explain what was happening:

I have a machine called ws1.domain.com. Its in the domain.com network. The mx record for domain.com points to gmail apps. When ws1 tried to send out mail to aaron@domain.com, it would deliver it to the local email box. This is not what I wanted – I wanted it to leave the machine and goto the gmail box. Everywhere else worked fine.

After some mistakes, I finally realized where the culprit lived…

In main.cf, the following variable was set:

mydomain = domain.com

This was as it was supposed to be. But, later on in the file, the following line existed:

mydestination = $mydomain, localhost.$mydomain, localhost

This was what was causing the local mail to be delivered locally. I removed the variables like such:

mydestination =

And now everything works. Yay.

Launch Screen Automatically

Monday, July 6th, 2009

Because the internet in the Crown building is as good as… well my parents 19.2K dialup – which drops pretty much every 5 minutes, I’ve had to use GNU screen extensively.

I’ve modified my .bash_profile page to have the following line:

exec /usr/bin/screen -R

This way it automatically reattaches to any screen it lost when it last disconnected. If none exists, it just creates a new session. Simple but very useful.

  • twitter loader

Follow me on twitter: @aaronsaray

The views on this website are my own and do not reflect the opinions of my employer or clients.
Creative Commons License Home | Open Source | Book | Music | Art | Bio | Resume | Contact
My Baby