Paul’s Linux Blog

Just Another Uber-Geek

Browsing Posts tagged network

I have decided enough is enough and ditched the useless nm-applet manager that was always greyed out and never worked since my first update after I installed Crunchbang.

I used nm-applet on Fedora and Ubuntu but recently since I moved to crunchbang it just never worked for me. this was sad as I used to rely on VPN in the manager for my connection to work, after this broke I was left trying to figure out how to connect to my work, I ended up installing kvpn which did the job but latter moved on to a great script that automates the setup and configuration that just works for me, so well I can even browse the web and work at the same time as the routing is good too, anyway if you want to know more about VPN see my other post.

Extract of wicd man page:

Wicd is designed to give the user as much control over behavior of net-
work connections as possible.  Every network, both wired and  wireless,
has  its  own profile with its own configuration options and connection
behavior.  Wicd will try to automatically connect only to networks  the
user  specifies  it should try, with a preference first to a wired net-
work, then to wireless.
For wired connections, users have many  options  for  determining  what
network  settings  to use.  Wicd allows creation of an unlimited number
of wired profiles, each of which has its own unique settings.  The user
can  choose  to  automatically  connect  to a selected default profile,
choose a profile from a pop-up window every time wicd connects, or have
wicd automatically choose the last profile used to manually connect.
For  wireless connections, users can select any number of wireless net-
works to automatically connect; wicd will choose the one with the high-
est signal strength to try to connect.

I decided to ditch the applet manager and install wicd as follows.

wi

Exmaple of wicd Manager.

Install WICD Manager

1) install the manaager

# apt-get install wicd

2) Configure the autostart of the manager

# cp  $HOME/.config/openbox/autostart.sh $HOME/.config/openbox/autostart.sh.bak
# vi $HOME/.config/openbox/autostart.sh

find the line that say's

# Launch network manager applet
#(sleep 1s && nm-applet) &

Comment it out and add the following lines after it

# Launch wicd network manager applet
(sleep 1s && wicd-client) &

You may wish to check the wicd demon runs as a service.

To do this you need to use a service manager such as BootUpManager aka 'bum'

or install a cmd tool like chkconfig.

I will use chkconfig for this example.

# chkconfig --list |grep wicd

To ensure wicd starts at boot up use:

# chkconfig wicd o

When you next log on you should find the new applet in your tool bar if not you can open it manually by typing:

# wicd-client.

Set up VPN to a MS Exchange or VPN Server on Command line.

This method of using the VPN via a script works great in crunchbang and I hope other linux systems where the gui is either not available or you prefer to use scripts rather than heavy memory hogging gui's.

Install PPTP Client

First of all we need to install the pptp application:

 # sudo apt-get install pptp-linux

This script will configure everything for you, that's right no messing about no configuring files, just let the script do the hard work for you.

Copy and paste the following into your favorite editor, I used vi

 vi /usr/local/bin/vpnconnect.sh
#!/bin/bash
function routeadd {
   route add -host 61.xxx.xxx.xxx dev ppp0
   route add -host 62.xxx.xxx.xxx dev ppp0
   route add -host 63.xxx.xxx.xxx dev ppp0
}
function makepptp {
   echo pty \"pptp VPN.SERVER.COM --nolaunchpppd\" >> /etc/ppp/peers/pptpvpn;
   echo remotename PPTP >> /etc/ppp/peers/pptpvpn;
   echo require-mppe-128 >> /etc/ppp/peers/pptpvpn;
   echo file /etc/ppp/options.pptp >> /etc/ppp/peers/pptpvpn;
   echo ipparam pptpvpn >> /etc/ppp/peers/pptpvpn;
pppd call pptpvpn &
}
if [ -a /etc/ppp/chap-secrets ];
		then
		rm /etc/ppp/chap-secrets
	echo $1 PPTP $2 '*' >> /etc/ppp/chap-secrets;
else
	echo $1 PPTP $2 '*' >> /etc/ppp/chap-secrets;
fi
 
if [ -e /etc/ppp/peers/pptpvpn ];
	then
	rm /etc/ppp/peers/pptpvpn;
	echo name $1 >> /etc/ppp/peers/pptpvpn;
	makepptp;
	sleep 8;
	routeadd;
else
	echo name $1 >> /etc/ppp/peers/pptpvpn;
	makepptp;
	sleep 8;
	routeadd;
fi

Replace "VPN.SERVER.COM" with the name or ip address of the VPN Server you are connecting to.

Configure the Routing.

"route add -host 63.xxx.xxx.xxx dev ppp0" This will enable you to communicate with servers on these address. (host name or IP address)

For example your pc maybe on 192.168.1.10 but your work PC may be on 172.19.100.5 to ensure you can connect to this machine your pc needs to route it's packets (data) on the 172 network address, to do this we would need the routing to be 172.0.0.0.

You can add as many routes as required but be careful as it gets harder to work out any errors with multiple routes.

To see your configured routes type:

 # route -

or to see the full resolved route table (takes longer to display) type:

 # route

You can now save and close the file.

Make the new script executable:

 # chmod +x /usr/local/bin/vpnconnect.sh

Now the script has been completed we need to run it and test the connection.

Subsitute the username and password for your vpn username and password, this maybe your work pc login credentials.

 # sudo vpnconnect.sh your_username your_password

Hopefully no errors came up when you ran the script.
You can run some tests to see if it is connected as follows:

 # ifconfig pptp

To disconnect your vpn connection type:

 # killall pppd

There are times when you want to be able to start, stop, restart, reload and even permantly stop  services from running.

I always run through my system services and ensure I have turned off all the services I do not wish to be running, this serves several good reasons:

1) Reduce's the amount of memory used.
2 Can make an increase in system performance.
3) Why run a service you don't need, that could be a security risk.
4) PC will boot faster.

How do I manage my services?

There are many ways to manage services on linux.

The services that start reside in the init.d and rc?.d folders in /etc.

To start and stop a service for example networking you would use:

 # sudo apt-get install pptp-linux
 # sudo /etc/init.d/networking stop
 # sudo /etc/init.d/networking start

Redhat uses these locations to start and stop services but also offers a shell command that can mange these services so they stay on or off permanently.

chkconfig - This command alows you to see all the services in a list and which of them are on or off in any runlevel.

NOTE:  A run level is the level the system is operating at this list is a guide to the levels not necessarily the setup that your linux uses.

1 - Single user mode
2 - Not used
3 - Full system no GUI
4 - Not used
5 - Full system with GUI

To find out what your default runlevel is you can look at the /etc/inittab file.

Using chkconfig

To see which services are configured as system services use:

 # sudo chkconfig --list

To turn off a service use:

 # sudo chkconfig --levels 345 sshd off

NTSYSV

Redhat also provides a command called ntsyv.

ntsysv - This is a text user interface that function as the above command.

It can be used to configure the running runlevel as follows:

 # sudo ntsysv

or for other runlevels use:

 # sudo ntsysv --level 345

What if I'm running Crunchbang.

In crunchbang these utilities are not installed, you will need to install them yourself if you wish to configure you services manually.

Use the following commands to install the above commands.

 # sudo apt-get install chkconfig

crunchbang does not have ntsysv but it does have a similar command called sysvconf.

 # sudo apt-get install sysvconf

I need a GUI not command line

If you really need that gui tool then use the humorously named BootUpManager aka BUM

 # apt-get install bum

This tool allows you to manage all your services as above but in a graphical way.

Remember when playing with services you need to be root, use sudo in front of all the commands before running them.

This week I decided to learn about irc?

I knew this was known as Internet relay chat and has been around a long time. I've met people who raved about it but I never found the use as I always used web forums of posed a question, but what about real time help? Queue IRSSI

I used irssi as it was pre-installed on my crunchbang, it's a terminal application, I personal like the command line so I fired it up.

First thing I saw was a command prompt? I quick Google brought up lots of information on irc and irssi. I soon realised I needed to type "/connect irc.freenode.net" this logged me into a server, ok straight forward.
Next to connect to a irc channel, I knew there was one for crunchbang so typed "/join #crunchbang" and volia I was engaged in a chat about subject matter I knew about. I learned to use /quit or /wc to exit and even tried running multiple sessions to servers.

All in all I like it, and that's why it is my topic of the week, why not give it a go yourself, there's lot's of like minded people out there who don't bite, not much anyway. :)

Powered by WordPress Web Design by SRS Solutions © 2010 Paul’s Linux Blog Design by SRS Solutions