blog hits

Web Counters

Saturday, July 18, 2009

share the internet connection in linux

i had the same problem when i started to explore the internet to find the solution to share the internet in my computer. I use Fedora 11. But the below mentioned method is a common way of sharing internet in any linux distributions.

first of all lets look at the topology of network we are going deal with.


{internet}-----(XXX0 / 10.0.0.1)-> PC-A -(YYY0/192.168.0.1)-----------(ZZZ0/192.168.0.2)-> PC-B

We need to share the internet connection to PC-B from PC-A. PC-A is directly connected to the internet via an network interface (such as eth0 or wlan0 or ppp0). We take that interface as XXX0. But please make sure to change the XXX0 to the appropriate network interface which u are connected to the internet.

same as that PC-B is connected to PC-A via interfaces YYY0, ZZZ0 respectively. Once again please make sure you substitute the interface names with the appropriate interface names of yours. (you can check the interface names by ifconfig command)

The architecture of sharing the internet is not hidden in the linux as microsoft does in thier OS. So we should enable the NAT in the internet connected PC, which works as a NAT router. and we should also enable the remote packet forwarding too. This is by default disabled. Now lets work it out...

1) Change to root (this is a must)

su - root

2) Enable IP forwarding

echo "1" > cat /proc/sys/net/ipv4/ip_forward

edit /etc/sysctl.conf

and set.....

# Controls IP packet forwarding

net.ipv4.ip_forward = 1

3) Configure NAT functionality

- remove excisting IPTABLE entries

iptables -F
iptables -t nat -F
iptables -t mangle -F

iptables -X
iptables -t nat -X
iptables -t mangle -X

- Now save the iptables rules

service iptables save
service iptables restart

- Set the nat assuming the internet interface is XXX0

iptables -t nat -A POSTROUTING -o XXX0 -j MASQUERADE
service iptables save
service iptables restart


4) Restart network

service network restart

here we go click the PC-Bs web browser and surf the internet.. Enjoy.

Linux is beautiful. And it gives us the real feeling of working on it. Coz we configure it for our own style. This tutorial is for novice users. For next level of linux users they can utilize the above setting according to their needs.

Monday, May 25, 2009

Create a recycle bin for linux console

Concept : when a user deletes a file that file is moved in to the folder $HOME/.junk

  1. Create the .junk folder in the /etc/skel directory.

    The content in this directory is copied in to the user home directory when the new user is created. This technique can be used to create the .junk directory in the users home directory.

    login as the root
    $ su - root
    password :
    #

    create the .junk directory
    # mkdir /etc/skel/.junk

  2. The envioromental variabble we create is WASTEBIN.

    The value of the variable will be $HOME/.junk - this enables the user to call the recycle bin directory from the command line.
    edit the file .bash_profile which is executed when the user logs in
    # vi /etc/skel/.bash_profile

    in that file add at the bottom
    export WASTEBIN=$HOME/.junk

  3. The command that we create is "del" this is alias to "rm" command.

    edit the .bashrc file
    # vi /etc/skel/.bashrc

    and append this text to that file to make an alias. add this to the file bottom
    alias rm=del

  4. design the "del" command

    In shell(bash) $1, $2, $3... $9 are the nine bash commanline arguments. So we use this predefine variables to pass the values to the "del" command.

    we can also use $* variable, which represent all those 9 variables at once. so the del command would be in the following format
    del ....

    create the file#
    # vi usr/local/bin/del

    then add
    mv $* $WASTEBIN

  5. change the execution permission to the del command

    # chmod +x /usr/local/bin/del

Sunday, May 24, 2009

download Fedora 10

Fedora is a Linux-based operating system that showcases the latest in free and open source software. Fedora is always free for anyone to use, modify, and distribute. It is built by people across the globe who work together as a community: the Fedora Project. The Fedora Project is open and anyone is welcome to join.

i386
[   ] Fedora-10-i386-disc1.iso                                19-Nov-2008 17:02   687M 
[   ] Fedora-10-i386-disc2.iso                                19-Nov-2008 17:02   674M   
[   ] Fedora-10-i386-disc3.iso                                19-Nov-2008 17:03   676M   
[   ] Fedora-10-i386-disc4.iso                                19-Nov-2008 17:03   691M   
[   ] Fedora-10-i386-disc5.iso                                19-Nov-2008 17:04   687M   
[   ] Fedora-10-i386-disc6.iso                                19-Nov-2008 17:04  80.1M   
[   ] Fedora-10-i386-DVD.iso                                  19-Nov-2008 16:56  3493M   
[   ] Fedora-10-i386-netinst.iso                              19-Nov-2008 16:53   129M  

x86 64
[   ] Fedora-10-x86_64-disc1.iso                              19-Nov-2008 18:29   688M   
[   ] Fedora-10-x86_64-disc2.iso                              19-Nov-2008 18:29   690M   
[   ] Fedora-10-x86_64-disc3.iso                              19-Nov-2008 18:29   688M   
[   ] Fedora-10-x86_64-disc4.iso                              19-Nov-2008 18:30   688M   
[   ] Fedora-10-x86_64-disc5.iso                              19-Nov-2008 18:31   691M   
[   ] Fedora-10-x86_64-disc6.iso                              19-Nov-2008 18:31   534M   
[   ] Fedora-10-x86_64-DVD.iso                                19-Nov-2008 18:21  3979M   
[   ] Fedora-10-x86_64-netinst.iso                            19-Nov-2008 18:17   130M  

Linux Principles

  • Everything is a file (including hardware)

    - in linux everything is a file including the hardware. There are three types of files

    text file

    Binary file

    Device file - hardware representatives


  • Small, single-purpose programs

    - small is beautifull concept


  • Ability to chain programs together to perform complex tasks

    - in other word.. its called piping. "|"


    example

    cat /etc/passwd | cut -f1 -d :

    this will read the file /etc/passwd and the content is cut with the delemeter ":" and the 1st part is shown


  • Avoid captive user interfaces

    - the basic work in linux is done in command. The GUI is the graphical representative of the command line execution.


  • Configuration data stored in text

    - all configurations are stored in plain text files


    example

    cat /etc/resolve.conf

    this will show the DNS database stored in linux. The name list is stored in plain text in the file /etc/resolve.conf

Change password in linux

passwd - entering just passwd would allow you to change the password. After entering passwd you will receive the following three prompts:

Current Password:
New Password:
Confirm New Password:

Each of these prompts must be entered and entered correctly for the password to be successfully changed.

passwd newperson

If you have just setup an account using the useradd command you would then type a command similar to the above command to set the password for the "newperson" account. Only root users have the ability to set passwords for other accounts.

basic linux commands


catSends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.

cat .bashrcSends the contents of the ".bashrc" file to the screen.


cd

Change directory

cd /homeChange the current working directory to /home. The '/' indicates relative to root, and no matter what directory you are in when you execute this command, the directory will be changed to "/home".

cd httpdChange the current working directory to httpd, relative to the current location which is "/home". The full path of the new working directory is "/home/httpd".

cd ..Move to the parent directory of the current directory. This command will make the current working directory "/home.





cd ~Move to the user's home directory which is "/home/username". The '~' indicates the users home directory.



cpCopy files

cp myfile yourfileCopy the files "myfile" to the file "yourfile" in the current working directory. This command will create the file "yourfile" if it doesn't exist. It will normally overwrite it without warning if it exists.

cp -i myfile yourfileWith the "-i" option, if the file "yourfile" exists, you will be prompted before it is overwritten.

cp -i /data/myfile .Copy the file "/data/myfile" to the current working directory and name it "myfile". Prompt before overwriting the file.

cp -dpr srcdir destdirCopy all files from the directory "srcdir" to the directory "destdir" preserving links (-p option), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another directory.




dd
dd if=/dev/hdb1 of=/backup/Disk duplicate.

The man page says this command is to "Convert and copy a file", but although used by more advanced users, it can be a very handy command. The "if" means input file, "of" means output file.


df


Show the amount of disk space used on each mounted filesystem.


less

less textfile
Similar to the more command, but the user can page up and down through the file.

The example displays the contents of textfile.



ln


Creates a symbolic link to a file.

ln -s test symlinkCreates a symbolic link named symlink that points to the file test Typing "ls -i test symlink" will show the two files are different with different inodes. Typing "ls -l test symlink" will show that symlink points to the file test.



locate

A fast database driven file locator.

slocate -uThis command builds the slocate database. It will take several minutes to complete this command. This command must be used before searching for files, however cron runs this command periodically on most systems.

locate whereisLists all files whose names contain the string "whereis".




logoutLogs the current user off the system.


ls


List files

lsList files in the current working directory except those starting with . and only show the file name.

ls -alList all files in the current working directory in long listing format showing permissions, ownership, size, and time and date stamp



moreAllows file contents or piped output to be sent to the screen one page at a time.

more /etc/profileLists the contents of the "/etc/profile" file to the screen one page at a time.





mvMove or rename files

mv -i myfile yourfileMove the file from "myfile" to "yourfile". This effectively changes the name of "myfile" to "yourfile".

mv -i /data/myfile .Move the file from "myfile" from the directory "/data" to the current working directory.



pwdShow the name of the current working directory



shutdownShuts the system down.

shutdown -h nowShuts the system down to halt immediately.

shutdown -r nowShuts the system down immediately and the system reboots.



whereisShow where the binary, source and manual page files are for a command

whereis lsLocates binaries and manual pages for the ls command.