Saturday, July 30, 2011

Sharing internet connection(3g or ethernet) over Wifi on Fedora

Here are the steps, that I used to share my Reliance Netconnect connection over the wifi, so that I can use it on my android phone.

Fist of all, connect to Reliance Netconnect on your linux system. You can use wvdial or network Manager for that. You can see this connection on ppp0 interface(could be different from system to system).

Reliance Connection:      ppp0
Wifi ad-hoc connection:  eth1

*interface name(eth1/ppp0) could be different from system to system. So please change it accordingly

Prepare WIFI interface(eth1):

# ifconfig eth1 up

Change the wifi on Ad-hoc mode
# iwconfig eth1 mode Ad-Hoc

Set the essid for shared network
# iwconfig eth1 essid hotspot

Set the key for the ad-hoc wifi
# iwconfig eth1 key 123456789

Set ip address to this interface
# ifconfig eth1 up 192.168.2.1 netmask 255.255.255.0



Set IP forwarding at kernel level:

# vim /etc/sysctl.conf
change entry "net.ipv4.ip_forward=0" to "net.ipv4.ip_forward=1"
# sysctl -p



Adding NAT ip rule in iptables:

# service iptables start
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
# service iptables save
# service iptables restart
# chkconfig iptables on


That is it. Your Linux system is sharing ppp0 internet connection over the wifi eth1 using essid "hotspot".


Connecting your phone with wifi:


1. Set the static IP configuration on your phone as follows:

    IP Address :       192.168.2.2
    Netmask    :        255.255.255.0
    Gateway    :        192.168.2.1
    DNS           :         192.168.2.1( if you are using dnsmasq or local dns on linux system else use your pppo  connection dns )

Note: skip the above part if you are using dhcp on the linux system.

2. Scan for the ad-hoc wifi network with essid "hotspot" and connect to it.

Now you can start surfing on your phone. :)

Note:

1. Your Android phone need to be rooted for connecting to Ad-hoc Network.

2. You can share your ethernet Lan connection over wifi using this method. Just need to replace ppp0 interface with eth0.

3. You can add the wifi preparation steps to a script file. You can use this script to start this next time.

Tuesday, April 5, 2011

Creating a PXE boot kickstart server Centos

Packages required: tftp, dhcp & syslinux

1. Install the required packages on the server. Syslinux is usually by default installed on the server.

#yum install tftp-server dhcp syslinux

2. Edit /etc/xinet.d/tftp file to run the tftp service under xinetd daemon. Modify the following lines in the conf file as follows:

disable                 = no
server_args             = -s /tftpboot

Make sure the both the lines should be exactly like this, because we are going to use the /tftpboot dir as default root-pxe dir. If the path given here in server-args is different from our pxe root dir, then we'll normally get "PXE-T01: File not found." error. Save the above file after making the changes.

3. Restart the xinetd services to start the tftp service and make it executable on startup.

#service xinetd start
#chkconfig xinetd on

4. Copy the required files from the Syslinux dir to /tftpboot dir.

#cp /usr/lib/syslinux/{pxelinux.0,menu.c32,mboot.c32,memdisk,chain.c32} /tftpboot/

5. Create PXE Menu directory.

# mkdir /tftpboot/pxelinux.cfg

6. Create dir for centos image in tftpboot dir. Suppose you  have centos 5.5 i386 and centos 5.5 x86_64 linux iamges, then create dir as follows.

# mkdir -p /tftpboot/images/centos/i386/5.5
# mkdir -p /tftpboot/images/centos/x86_64/5.5

7. mount the linux iso image that you have to /mnt and copy initrd.img and vmlinuz files from the /mnt/images/pxeboot dir to the respective tftpboot image paths that you have created.

# mount -o loop /home/centos-5.5.i386.iso /mnt
# cp /mnt/images/pxeboot/{ initrd.img, vmlinuz} /tftpboot/images/centos/i386/5.5
# umount /mnt
# mount -o loop /home/centos-5.5.x86_64.iso /mnt
# cp /mnt/images/pxeboot/{ initrd.img, vmlinuz} /tftpboot/images/centos/x86_64/5.5
# umount /mnt

8. Edit dhcpd.conf file and add the following lines to the configuration. Use your pxe server ip in place of the 000.000.000.000.

allow bootp;
allow booting;
filename "pxelinux.0";
next-server 000.000.000.000;
option option-128 code 128 = string;
option option-129 code 129 = text;



9. Create a file /tftpboot/pxelinux.cfg/default for default menu and add the following.

default menu.c32
prompt 0
timeout 300
ONTIMEOUT local

MENU TITLE PXE MENU

LABEL Centos 5.5 x86
          MENU LABEL Centos 5.5 x86
          KERNEL images/centos/i386/5.5/vmlinuz
          APPEND ks initrd=image/centos/i386/5.5/initrd.img ramdisk_size=100000 ksdevice=eth0 ip=dhcp url --url http://path to ks file

 LABEL Centos 5.5 x86_64
          MENU LABEL Centos 5.5 x86_64
          KERNEL images/centos/x86_64/5.5/vmlinuz
          APPEND ks initrd=image/centos/x86_64/5.5/initrd.img ramdisk_size=100000 ksdevice=eth0 ip=dhcp url --url http://path to ks file


10.  Restart the dhcpd server and restart the xinetd service.

#service dhcpd restart
#service xinetd restart

You can add more images to your pxe configuration later on in the similar way.