March 16

Linux: Ubuntu – Configuring the network from the command line

Your main network configuration file is /etc/network/interfaces

Desired new sample settings:
=> Host IP address 192.168.1.100
=> Netmask: 255.255.255.0
=> Network ID: 192.168.1.0
=> Broadcast IP: 192.168.1.255
=> Gateway/Router IP: 192.168.1.254
=> DNS Server: 192.168.1.254

Open network configuration file
$ sudo vi /etc/network/interfacesOR$ sudo nano /etc/network/interfaces

Find and remove dhcp entry:by Vivek Gite
iface eth0 inet dhcp

Append new network settings:

iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254

Save and close the file. Restart the network:
$ sudo /etc/init.d/networking restart
Task: Define new DNS servers

Open /etc/resolv.conf file
$ sudo vi /etc/resolv.conf

You need to remove old DNS server assigned by DHCP server:
search myisp.com
nameserver 192.168.1.254
nameserver 202.54.1.20
nameserver 202.54.1.30

Save and close the file.
Task: Test DNS server

$ host cyberciti.biz
Network command line cheat sheet

You can also use commands to change settings. Please note that these settings are temporary and not the permanent. Use above method to make network changes permanent or GUI tool as described below.
Task: Display network interface information

$ ifconfig
Task: Take down network interface eth0 / take a network interface down

$ sudo ifconfig eth0 downOR $ sudo ifdown eth0
Task: Bring a network interface eth0 up

$ sudo ifconfig eth0 upOR$ sudo ifup eth0
Task: Change IP address and netmask from command line

Activate network interface eth0 with a new IP (192.168.1.50) / netmask:
$ sudo ifconfig eth0 192.168.1.50 netmask 255.255.255.0 up
Task: Display the routing table

$ /sbin/route OR$ /sbin/route -n
Output:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
localnet * 255.255.255.0 U 0 0 0 ra0
172.16.114.0 * 255.255.255.0 U 0 0 0 eth0
172.16.236.0 * 255.255.255.0 U 0 0 0 eth1
default 192.168.1.254 0.0.0.0 UG 0 0 0 ra0

Task: Add a new gateway

$ sudo route add default gw 172.16.236.0
Task: Display current active Internet connections (servers and established connection)

$ netstat -nat
Task: Display open ports

$ sudo netstat -tulpOR$ sudo netstat -tulpn
Task: Display network interfaces stats (RX/TX etc)

$ netstat -i
Task: Display output for active/established connections only

$ netstat -e
$ netstat -te
$ netstat -tue

Where,

-t : TCP connections
-u : UDP connections
-e : Established

Task: Test network connectivity

Send ICMP ECHO_REQUEST to network hosts, routers, servers etc with ping command. This verifies connectivity exists between local host and remote network system:
$ ping router
$ ping 192.168.1.254
$ ping cyberciti.biz

See simple Linux system monitoring with ping command and scripts for more information.
Task: Use GUI (Graphical Configuration) network Tool

If you are new, use GUI configuration tool, type the following command at terminal:
$ network-admin &

Above command is Ubuntu’s GUI for configuring network connections tool.
Final tip – Learn how find out more information about commands

A man page is your best friend when you wanted to learn more about particular command or syntax. For example, read detailed information about ifconfig and netstat command:
$ man ifconfig
$ man netstat

Just get a short help with all command options by appending –help option to each command:
$ netstat –help

Find out what command is used for particular task by searching the short descriptions and manual page names for the keyword:
$ man -k ‘delete directory’
$ apropos -s 1 remove

Display short descriptions of a command:
$ whatis rm
$ whatis netstat

 

By Vivek Gite

Category: Linux | Comments Off on Linux: Ubuntu – Configuring the network from the command line
March 16

Linux: Centos – Installing VBOX Guest Additions

How to install Virtual Box Guest Additions in CentOS

log in as root and type in terminal

yum install gcc -y

yum install kernel-headers -y (The need for this appears to vary by Redhat/Fedora version)

yum install kernel-devel -y

restart the system

now go to the VBox Addition directory in your /media directory and type:

sh VBoxLinuxAdditions.run

restart the system again

By: yoyo

Category: Linux | Comments Off on Linux: Centos – Installing VBOX Guest Additions
February 15

Linux: Backtrack networking options including autostart

Note: Commands listed should be run as root or with sudo (switch user do) command.

Enter the following command to enable or start your networking in BackTrack
/etc/init.d/networking start

This command will start all the interfaces in the /etc/network/interfaces file.

Below are more information in how to enable or start networking in Backtrack.

Setting your interfaces to get ip addresses via DHCP.
See my sample /etc/network/interfaces file.

root@wiztechie:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp

auto ath0
iface ath0 inet dhcp

auto wlan0
iface wlan0 inet dhcp

Setting your interfaces manually or having static ip addresses.
See my sample /etc/network/interfaces file.

auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1

Setting up your nameserver.
See my sample /etc/resolv.conf file.

root@wiztechie:~# cat /etc/resolv.conf
nameserver 192.168.0.1

If you only want specific interfaces to get ip address via the DHCP (in this example, let’s say eth0 and wlan0 only) then remove every thing else for the file with the exception of the lo interface.
See my sample /etc/network/interfaces file.
Note: Backup first your /etc/network/interfaces file if you’re having some doubt with what you are doing, in this way you can revert back to the original file. To do this enter cp /etc/network/interfaces /etc/network/interfaces.bak (this create a backup of the /etc/network/interfaces file)

root@wiztechie:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet dhcp

If you want to autostart or run this at startup, enter the command.

update-rc.d networking defaults

Category: Linux | Comments Off on Linux: Backtrack networking options including autostart
January 22

Linux: lsof

lsof is a very powerful “list open files” command.

eg:  lsof -i -n -P : grep firefox
lsof -PNL -i4

Overview

LiSt Open Files is a useful and powerful tool that will show you opened files. In Unix everything is a file: pipes are files, IP sockets are files, unix sockets are files, directories are files, devices are files, inodes are files…

Useful Examples

So in this tangle of files lsof listst files opened by processes running on your system.

When lsof is called without parameters, it will show all the files opened by any processes.

lsof | nl

Let us know who is using the apache executable file, /etc/passwd, what files are opened on device /dev/hda6 or who’s accessing /dev/cdrom:

lsof `which apache2`
lsof /etc/passwd
lsof /dev/hda6
lsof /dev/cdrom

Now show us what process IDs are using the apache binary, and only the PID:

lsof -t `which apache2`

Show us what files are opened by processes whose names starts by “k” (klogd, kswapd…) and bash. Show us what files are opened by init:

lsof -c k
lsof -c bash
lsof -c init

Show us what files are opened by processes whose names starts by “courier”, but exclude those whose owner is the user “zahn”:

lsof -c courier -u ^zahn

Show us the processes opened by user apache and user zahn:

lsof -u apache,zahn

Show us what files are using the process whose PID is 30297:

lsof +p 30297

Search for all opened instances of directory /tmp and all the files and directories it contains:

lsof +D /tmp

List all opened internet sockets and sockets related to port 80:

lsof -i
lsof -i :80

List all opened Internet and UNIX domain files:

lsof -i -U

Show us what process(es) has an UDP connection opened to or from the host www.akadia.com at port 123 (ntp):

lsof [email protected]:123

lsof provides many more options and could be an unvaluable foresinc tool if your system get compromised or as daily basis check tool.

Category: Linux | Comments Off on Linux: lsof
January 11

Linux: Resetting a Forgotten Root Password

If you have forgotten the root password it is possible to set a new one as follows:

Interrupt the boot at the GRUB stage and boot to runlevel 1, AKA single user mode. Interrupt GRUB by typing a character such as “space” then append to the kernel line by typing “a”, backspacing through “rhgb quiet” and appending ” 1<enter>”. This will give you a root shell and not a login prompt. From there you can use the “passwd” command to set a new root password.

Other user passwords can be reset, and other administrative tasks can be performed as well. Exiting the single user root shell will boot to the multi-user mode defined in /etc/inittab.

CentOS-6 Note: Due to an upstream SELinux bug the root password cannot be reset on a fresh install of CentOS-6 without an additional step. Booting with “selinux=0” appended to the grub kernel line, or doing “setenforce 0” after logging in and before attempting to reset the password are work-arounds. This is corrected by applying already-released errata updates.

Category: Linux | Comments Off on Linux: Resetting a Forgotten Root Password