Archive for the 'centos' Category

How to assign range of IP addresses in Linux?

ip address exampleAs we know Linux allows to assign almost unlimited number of IP addresses to its interfaces. Such additional IPs applied to the same NIC are known as secondary IP addresses or just secondaries. Some time ago i faced a problem on how to apply about 500 IP addresses to one Linux box and then ensure that all of them get online after Linux reboots. There are several ways to accomplish this taks so i would like to share them all.

Shell script with ifconfig commands

This is one of the most inefficient ways to get many IP addresses applied to one network interface. Anyways it allows to create as many aliases for the interface as you like so you should create shell script and execute it every time Linux boots.

touch /path/to/script.sh
chmod +x /path/to/script.sh
vi /path/to/script.sh

Now you should add there shell lines which will apply IP addresses, e.g. the following one applies 60 IP addresses to eth0 interface:

for n in {3..63};  do ifconfig eth0:${n} 10.10.10.${n} netmask 255.255.255.0 up; done

If you type ‘ifconfig’ now you will very long output like this one:

eth0:3  Link encap:Ethernet  HWaddr 00:50:8D:D1:24:DB
          inet addr:10.10.10.3  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:10 Base address:0x2000 

eth0:4  Link encap:Ethernet  HWaddr 00:50:8D:D1:24:DB
          inet addr:10.10.10.4  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:10 Base address:0x2000

...

eth0:63  Link encap:Ethernet  HWaddr 00:50:8D:D1:24:DB
          inet addr:10.10.10.63  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:10 Base address:0x2000

If you decide to delete those IPs you can run the following line as a remedy:

for n in {3..63};  do ifconfig eth0:${n} 0.0.0.0 &> /dev/null; done

Once you finished editing /path/to/script.sh script you should add it to startup, so put the line /path/to/script.sh into /etc/rc.local file that Linux executes every time it boots. Please notice that in various distributions this file may be missing so consult with distro’s docs to get where it is stored.

Redhat/Centos/Fedora network scripts

Users of these Linux distributions can apply ranges of IP addresses using ifcfg-eth0-range0 files which are read during initialization of network interfaces during boot up process. The following example will make Linux to apply 200 IP addresses to eth1 during booting:

[root ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth1-range0

IPADDR_START=192.168.1.1
IPADDR_END=192.168.1.200
CLONENUM_START=10

CLONENUM_START value specifies starting identifier of alias that will be applied to eth1 interface, in above example the first 192.168.1.1 will be assigned to eth1:10 alias. The last IP of the range 192.168.1.200 will be applied to eth:210 sub-interface. This is totally easy approach.

Loopback interface

Did you know that by one line presented below you assign 1022 virtual IP addresses to your Linux system? Here it is:

ifconfig lo:0 10.0.0.1/22

Now you can make sure of this by pinging IPs from that range (10.0.0.1 – 10.0.3.254).

[root ~]#ping 10.0.0.1 -c 1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.063 ms

--- 10.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.063/0.063/0.063/0.000 ms

...

[root ~]#[root@whitehorse /]# ping 10.0.3.254 -c 1
PING 10.0.0.1 (10.0.3.254) 56(84) bytes of data.
64 bytes from 10.0.3.254: icmp_seq=1 ttl=64 time=0.063 ms

--- 10.0.3.254 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.063/0.063/0.063/0.000 ms

If you still feel that the first suggested way meets your requirements better than the third one please read more about loopback interface at wikipedia — loopbacks are much more useful than aliases in most cases.

Hope it helps!

The easiest way to split and merge pdf files in Ubuntu

The easiest way to split, merge or edit pdf files in Ubuntu is to use pdftk utility. This rather old (latest version was released in 2006) but still simple and powerful program can be installed in Ubuntu (Debian or any deb-family Linux distribution) by the following command in terminal:

sudo aptitude install pdftk
(if you run Fedora, RedHat or CentOS use this one: sudo yum install pdftk)

Split large pdf into many one-page files:

pdftk largepdfile.pdf burst

(as the result you will get many small files like pg_0001.pdf, pg_0002.pdf and so on).

Merge files into one PDF file:

pdftk *.pdf cat output onelargepdfile.pdf

pdftk is extremely powerful and makes it possible to do almost anything with input pdf files. Thus above two commands are just examples showing how to split and merge pdf files in Ubuntu easily.

16 GB encrypted candy file

Update: as far as cryptoloop is vulnerable and is not maintained I don’t recommend using below approach for creating encrypted for for those of you who require strong security. Use truecrypt to create encrypted filesystem within a file instead.

passwords.txtToday it came to my mind that it is time to make sensitive information stored on my usb flash drive encrypted but still transportable and easy to use. But I don’t want to have whole my 32 GB usb drive fully encrypted using truecrypt or something similar. It is just toooo slow. I also don’t want to use GPG for uncompressing files and directories every time I would like to read them and then create new GPG compressed file every time I save changes. This eats too much of my time and system resources. At the same time it is necessary to be able to use that usb drive under windows, mac, linux whatever (read/write files) but still have my directory structure with sensitive files encrypted. Here is the solution: create encrypted filesystem within a file named, say, 16GB.candy.bin that could be stored on regular windows formatted usb flash drive and then mounted under Linux using the password.

When it becomes necessary I can mount that 16GB.candy.bin as the regular ext3 filesystem with all those stuff like permissions, ownership etc. that is available on ext3 but not in FAT or NTFS. On my windows formatted flash drive candy takes only 16 GB so I can use the rest of space to store not so sensitive information like mp3, movies or photos. Moreover I on windows or linux to read it.

Let’s create that 16GB.candy.bin file with encrypted ext3 filesystem (read below explanations below carefully before just to copy/paste commands into CLI):

[root@artemn root]# cd /path/to/candy/

[root@artemn root]# modprobe cryptoloop

[root@artemn root]# modprobe aes

[root@artemn root]# dd if=/dev/urandom of=16GB.candy.bin bs=1048576 count=16000

[root@artemn root]# losetup -e aes /dev/loop0 16GB.candy.bin

[root@artemn root]# mkfs.ext3 /dev/loop0

[root@artemn root]# tune2fs -i 0 -c 0 /dev/loop0

Here are some points: using above commands we create encrypted file of 16 GB so if you need to have more or less just change “count=16000″ in dd line. “count=16000″ means 16GB so “count=20″ means 20MB. Path ‘/path/to/candy/’ is for example only so you should change it to real directory that is able to host encrypted file (16 GB in above example). Command losetup is present in most Linux distributions (btw I recommend Ubuntu especially newly released Lucid Lynx) but if it is not use your disro’s packet manager to install it or compile from sources (for super geeks only, Mr. Stallman if you read this article — Hello). Reader, you can replace “/dev/urandom” in dd line with “/dev/zero” that will make that command to finish faster but will lower security level of resulting file (read about AES for better understanding). You will need to enter the password when running losetup command so make sure it safe and long enough like ‘6U2sAsR37Hn8122dGsaPrew1twt’ but not ‘abc123′ or ‘iloveyou’.

Once commands are done you will get 16GB.candy.bin containing encrypted ext3 filesystem. You can store this file where ever you want, say, on a flash drive. If you loose it nobody won’t be able to open it until he (or she!) cracked AES encryption (use long passwords to prevent this). As the next step it is required to mount filesystem and store some files/directories in it:

[root@artemn root]# mkdir -p /mnt/candy

[root@artemn root]# cd /path/to/candy/

[root@artemn root]# mount -t ext3 -o loop,encryption=aes 16GB.candy.bin /mnt/candy

[root@artemn root]# cd /mnt/candy

[root@artemn root]# #save files, edit them, view or anything you want

[root@artemn root]# cd /

[root@artemn root]# umount /mnt/candy

When you unmount 16GB.candy.bin the changes are already saved there so it’s not required to compress and encrypt anything unlike with GPG.

P.S. This post is inspired by Loopback tricks article. Thanks to the author. Good luck!

Install Ruby 1.8.7 from sources in Centos 5.5

Centos 5.5 official repository is rather outdated for today so the latest Ruby available there is 1.8.6. If you need a newer version e.g. 1.8.7 you should install if from sources:

0. Install prerequisites:

sudo yum install gcc zlib zlib-devel

1. Download the latest version of Ruby from project’s FTP:

cd /usr/src/
sudo -s
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.gz
tar -xvzf ruby-1.8.7.tar.gz
cd ruby-1.8.7
./configure --enable-pthread
make
make install

2. Check ruby’s version is 1.8.7:

[root@li110-222 ~]# /usr/local/bin/ruby -v
ruby 1.8.7 (2008-05-31 patchlevel 0) [i686-linux]

That’s it!

Top 3 Linux HTML editors

This post is dedicated to quality html editors for Linux and Ubuntu operating system in particular. You may think that nowadays nobody uses offline editors as there are so many content management systems (CMS) like Drupal (my favourite one), Wordpress, Joomla etc. which contain embedded visual html editors. But today I made sure myself that sometimes it’s real pain to draw a 10×20 table using Wordpress’s editor…

Text editors like gedit, emacs, nano or vi will certainly live forever but thankfully there are numerous visual html editors for my Ubuntu :) They are sometimes called WYSIWYG editors, it mean “What You See Is What You Get”.

1. Quanta Plus

This is KDE/Qt visual html editor available as binary package for numerous Linux distributions
including Debian and Ubuntu. From developers’ site:

Quanta Plus is a highly stable and feature rich web development environment.
The vision with Quanta has always been to start with the best architectural
foundations, design for efficient and natural use and enable maximal user
extensibility.

In order to install it in Debian/Ubuntu run the following CLI command:

sudo apt-get install quanta

Fedora, Centos, Redhat users type this:

sudo yum install kdewebdev

I found Quanta html editor extremely useful, this is just an outstanding application of this
field.

2. Bluefish

Bluefish HTML editor logoBluefish is a powerful editor targeted towards programmers and webdesigners,
with many options to write websites, scripts and programming code. Bluefish
supports many programming and markup languages, and it focuses on editing
dynamic and interactive websites.

I found this really versatile html editor. Besides HTML/CSS it handles C,
Java, Perl, Python, XML and others.

Ubuntu and Debian users type:

sudo apt-get install bluefish

Fedora/Redhat/Centos:

sudo yum install bluefish

Gentoo:

emerge bluefish

3. Screem

SCREEM is a web development environment. It’s purpose is to increase
productivity when constructing a site, by providing quick access to commonly
used features. While it is written for use with the GNOME desktop environment
in mind it does not specifically require you to be running it, just have the
libraries installed.

This is one of the most user-friendly Gnome HTML editor. Its simple interface
brings extremely powerfull HTML editor so if like minimalistic design Screem
is your choice.

Update: below is the bottom line from Linux.com’s review of three Linux HTML editors (Quanta Plus, Blowfish,
Screem). I found that review after I wrote this post.

  • If you use GNOME, use Screem. It’s a fast, simple, and powerful tool for web editing. However, it does not have the large feature sets that Bluefish and Quanta Plus have, especially for languages other than those directly related to Web page editing.
  • If you use GNOME and need the more powerful features of Quanta Plus, load the required libraries and run it.
  • If you use KDE and want a code editor, choose Quanta Plus. Ignore the WYSIWYG capabilities and take advantage of the tremendous editing capabilities, especially for CSS style sheets.
  • If you use Xfce, Quanta Plus should run fine. Screem would still require loading additional libraries.
  • Finally, if you use GNOME, find that Screem does not meet all your needs, and you don’t want to bother with loading the KDE-native Quanta Plus, then load Bluefish. It is nearly as capable as Quanta Plus, but will run well without a lot of fussing with libraries.

Information improvisation: Pass your 70-293 exams in first try by using our guaranteed cissp exam questions & HP0-Y31 tutorials and best quality 70-686 dumps along with HP0-S23.




Pages: 1 2 3 4 Next
Friendly Sites:Who is behind Linux Screw?
GeekyBits³ | Bash Cures Cancer | OMG! Ubuntu!
My SysAd Blog | Web Upd8
ZEPY | Linux config Wiki | Planet Sysadmin
a non-geek's linux notes | Linux Today
TuxArena: The arena of Tux | LinuxAlt.Com
My name is Artem N. (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››