Posts Tagged ‘command line’

Bring up network interface and set up network connection on Fedora Linux (command line)

Saturday, March 15th, 2008

Have you ever tried firing up a Linux VMware virtual machine configured with a static IP address on another machine? I did and I got into trouble with the local network and the Internet access.

In my case the vm was created by VMware Server on Linux and then copied onto my Mac and loaded in VMware Fusion. The appliance run in level 3 so it did not have any graphical environment (like KDE or Xfce) installed so all the configuration needed to be done on the command line.

The first symptom there was something wrong could be observed during the boot process when the following message popped up:

“Bringing up interface eth0: pcnet32 device eth0 does not seem to be present, delaying initialisation [FAILED]“.

After logging in as root I run this command just to make sure that was the case:

# /sbin/ifup eth0

… and got pretty much the same message as the one above.

I had a look at the VMware Fusion network device settings to ensure my wireless network card was bridged and connected and then run a set of commands described below.

1. Display all available network interfaces
# /sbin/ifconfig -a
eth1 Link encap:Ethernet HWaddr 00:0C:29:3E:42:B1
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:17 Base address:0x1080
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 b) TX bytes:560 (560.0 b)

2. eth1 is down, so let’s assign some IP address and the subnet mask to it (please note we do not use DHCP here)
# /sbin/ifconfig eth1 10.0.1.7 netmask 255.255.255.0

3. Check the current routing table
# /sbin/route
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 * 255.255.255.0 U 0 0 0 eth1

4. Specify default gateway
# /sbin/route add default gw 10.0.1.1

5. Last step - specify the name server address using a command line editor called vi
# vi /etc/resolv.conf
nameserver 10.0.1.1

(:wq to save the changes and quit)

6. Voila, the routing table now shows everything has been set up correctly
# /sbin/route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 * 255.255.255.0 U 0 0 0 eth1
default 10.0.1.1 0.0.0.0 UG 0 0 0 eth1

That’s it, your virtual machine is back on the network and you can now check it by pinging any domain you like. And to make these changes available after reboot you might want create/edit the /etc/sysconfig/network-scripts/ifcfg-eth1 file. My one has the following contents:

DEVICE=eth1
BOOTPROTO=static
BROADCAST=10.0.1.255
HWADDR=00:0C:29:3E:42:B1
IPADDR=10.0.1.7
NETMASK=255.255.255.0
GATEWAY=10.0.1.1
NETWORK=10.0.1.0
ONBOOT=yes

Report recently changed files with the directory hierarchy preserved (command line)

Tuesday, December 11th, 2007

This little command is very useful eg if you want to find out what files in your project have been modified recently. The beauty of the script is not only it outputs a list of files in your terminal but it also zips them up (or tars in this case) preserving the whole hierarchy of folders. The tar file can then be gzipped, bzip2ed or simply untarred so you can review the folders structure and your modified files.

Here’s an example of a command that displays the files modified within last two weeks on the screen, tars them and saves the tar file on your desktop. I tested this script both on the Mac and Linux.

$ tar cvf - `find /var/www/my_project -type f -mtime -14 -print` > ~/Desktop/project_recent_changes.tar

Capture Unix top command output into a file

Wednesday, November 21st, 2007

Firstly, you need to make sure that your top command does not redisplay the output. This is what you do on Linux and Mac OS:

Linux:

$ top -b -n 1

Mac OS X:

$ top -l 1

(Note that the first sample displayed will have an invalid %CPU displayed for each process, as it is calculated using the delta between samples. (from the top manual))

You can use a standart Unix command in order to save the details to a file:

$ top -b -n 1 > my_top_report.txt