Install Debian on Android

This is a minimalistic how-to to get a Debian environment running on almost any (rooted) android phone. I adopted the method here: http://www.saurik.com/id/10 to be more universal and added some new features.

Preparing the Debian Image

You will need access to a computer dunning a Debian based distribution to create the image for you phone. I used Ubuntu 10.04. To create the image you need to install a program called debootstrap. debootstrap will allow you to create a mini Debian install in your image.

After installing debootstrap you will need to create a filesystem image for android to use and for debootstrap to install Debian to. You can use the dd command to create the image. In my example below I made a 800MB image. Once the image is made you need to format it to a Linux file system.

Once your image it formated you should mount it and then run debbootstrap.

Below are my example commands, you may want/need to change them to fit your environment. Such as the Debian mirror, file size, etc.

sudo -s
apt-get install debootstrap
dd if=/dev/zero of=debian.img seek=838860800 bs=1 count=1
mke2fs -F debian.img
mkdir debian
mount -o loop debian.img debian/
debootstrap --verbose --arch armel --foreign lenny debian http://ftp.us.debian.org/debian
umount debian/
rm -r debian/

Prepairing the Debian boot script

Below is my Debian boot script (named bootdebian). I created it off the boot Ubuntu script for the HTC Droid Incredible, but modified it. My script includes the ability to become root if you are not already root, and it will mount your Incredible’s SD card and internal memory inside Debian so that you can easily move files in and out of your Chrooted environment. I also fixed some small errors on the other script. If you are not using the HTC Incredible you will want to change lines 38-47 to reflect your phone’s memory mount points.

EDIT 10/18/10:

Not everybody’s phone will use “/dev/block/mtdblock3″ for the /system mount point. Type the mount command to see what the propper mount point is on your device. The one used in this guide is for the HTC Incredible.

if [[ $EUID -ne 0 ]]
then
echo "Becoming ROOT!"
su -c bootdebian
exit 1
fi

echo "Mounting system as R/W"
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system

echo "Setting some stuff up.."
export bin=/system/bin
export img=/mnt/sdcard/debian.img
export mnt=/data/local/debian
export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
if [ ! -d $mnt ]
then
mkdir $mnt
fi

echo "Mounting the Linux Image"
mknod /dev/block/loop5 b 7 0 #may already exist
losetup /dev/block/loop5 $img
mount -t ext2 -o noatime,nodiratime /dev/block/loop5 $mnt
mount -t devpts devpts $mnt/dev/pts
mount -t proc proc $mnt/proc
mount -t sysfs sysfs $mnt/sys

echo "Setting Up Networking"
sysctl -w net.ipv4.ip_forward=1
echo "nameserver 8.8.8.8" > $mnt/etc/resolv.conf
echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf
echo "127.0.0.1 localhost" > $mnt/etc/hosts

echo "Mounting sdcard and emmc in /mnt"
if [ ! -d $mnt/mnt/emmc ]
then
mkdir $mnt/mnt/emmc
fi
busybox mount --bind /mnt/emmc/ $mnt/mnt/emmc
if [ ! -d $mnt/mnt/sdcard ]
then
mkdir $mnt/mnt/sdcard
fi
busybox mount --bind /mnt/sdcard/ $mnt/mnt/sdcard

echo "Entering CHROOT "
echo " "
chroot $mnt /bin/bash

echo " "
echo "Shutting down CHROOT"
umount $mnt/mnt/emmc
umount $mnt/mnt/sdcard
sysctl -w net.ipv4.ip_forward=0
umount $mnt/dev/pts
umount $mnt/proc
umount $mnt/sys
umount $mnt
losetup -d /dev/block/loop5
mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system

Now move both the above script and the debian.img file you made to your phone’s memory card.

Finishing up the Image

Now we need to finish up the install on your phone. Upen the terminal app you plan to use on your phone, I recommend ConnectBot. First we will re-mount the system partition as Read/Write, them move out bootdebian script over, make it executable, then remove it from the SD card. Then we run the bootdebian script and run the second stage of debootstrap.The second stage of debootstap will take a while, it took me 15 minutes, let it run. Once debootstrap has finished we will add the official Debian repository into the system, then use apt-get to remove the files left over by debootstap. Here are the commands:

su
mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
cat /sdcard/bootdebian > /system/xbin/bootdebian
rm /sdcard/bootdebian
chmod 777 /system/xbin/bootdebian
bootdebian
/debootstrap/debootstrap --second-stage
echo 'deb http://ftp.us.debian.org/debian lenny main' > /etc/apt/sources.list
apt-get autoclean
apt-get update
exit

You are done!

Now you can run “bootdebian” anytime from your phone’s tereminal to enter a full Debian system. You can apt-get install any Debian package that has been compiled to armel. :)

If you want to go further you can install X, and a VNC server. This would allow you to VNC into the Debian system from your phone giving you a full X enviroment.

Now go enjoy your full Linux distribution on your phone!


HTC Incredible Virtual CD-ROM Hack

The official HTC Incredible 2.2 update added a new feature to the ROM. When the phone is connected to a computer via USB, even if the memory card is not mounted, it will act as a virtual CD-ROM. It basically justs acts as a CR-ROM drive with the disk image found in  /system/etc/CDROM.ISO. The default ISO was some annoying Verizon thing. Most (rooted) users simply deleted the ISO from their system. I however found a way to make this feature a bit more useful.

Enabling and Disabling the CD-ROM the Right Way

The first way most people disabled this was to delete the ISO. This is not the correct way of doing it. Just deleting the file will still have the phone show an empty CD-ROM drive when plugged in to a computer. There is a nice ON/OFF switch for the CD-ROM that can be changed by anyone (non-rooted users) To enable/disable the CD-ROM feature follow these steps:

  1. Dial ##7764726
  2. Press Call
  3. Enter the password 000000 (6 zeros)
  4. Select Feature Settings
  5. Select CD-ROM
  6. Choose Enable or Disable
  7. Press Menu
  8. Select Commit Modifications (Don’t worry if it says no settings changed)
  9. Press Home

Using Your Own ISO

The ISO file that is mounted needs to be named CDROM.ISO in /system/etc/. So, after deleting the default ISO image (via the good old rm command) you can replace it with any ISO image you want. However this will be difficult with large ISOs and it will be a pain to mount system with R/W access and use the command line every time you want to change the ISO. So I propose this alternate solution, use a symbolic link! I made a symbolic link in /system/etc/CDROM.ISO that points to a CDROM.ISO on my internal memory card. To do this run this command as root:

rm /system/etc/CDROM.ISO  #if you have not yet deleted the CD-ROM image
ln /emmc/CDROM.ISO /system/etc/CDROM.ISO

Replace /emmc/ with /sdcard/ if you want to use your SD card and not the phone’s internal memory.

Finishing Up

Now place a ISO file on either your SD card or internal memory and it should be mounted as a CD-ROM drive. Ill let you be creative with what you could put in there (*cough* auto-run scrips*cough*). Unfortunately I cannot seem to get computers to boot off the ISO using this method. I’m guessing that it is because when the Incredible mounts the ISO it strips the boot flag. Also, since this hack will make the Incredible always access either your internal memory or your SD card, when selecting mount over USB the drive holding the ISO will be busy or in use by the system and sometimes will not mount on the computer. This can be fixed by force unmounting the drive (in your phone’s settings menu) or by temporarily disabling the CD-ROM feature (see above).

To my knowledge this hack only applies to the HTC Incredible with the official 2.2 build or ROMs built off of the official 2.2 build. Please let me know in the comments if this works on any other phones.


Nintendo DS WiFi Hacks and Tools

While searching the internet for something entirely unrelated I came across a copy of aircrack/aireplay and some packet capture programs for the Nintendo DS. With them you can use the DS to do some limited hacking and wireless security. Here are the four programs:

DSBlue

This program is also known as “MyFirst”. One of it’s many features is displaying live packet data that the DS picks up. It cannot save data and you can not pause the stream so it it not too useful, but it is still nice to play with and see what traffic is going over the air. You can assess this tool in AP Settings->Packer Spy.

DSBlue Wifi Spy

Reference site here: http://forum.gbadev.org/viewtopic.php?t=11233 and here:http://www.scdev.org/forum/index.php?topic=6335.0

Wifi Lib Test

This application started out as a tester for the DS’s homebrew WiFi library. It also has the ability to show live packet data. This tool also comes with a few other useful utilities, but like DSBlue, it lacks the ability to save the captured data to a file.

DS WiFi LIB Test

AireplayNDS

Yes, this is Aireplay for the Nintendo DS! It is limited and can only do Broadcast Deauthentification, which while useful, the computer that you would be using to capture the packets (as the DS is unable to) could also probably do this. But it can still be fun to deauthenticate people from their wifi ;)

Aireplay NDS

Reference: http://forum.gbadev.org/viewtopic.php?t=12666

AirCrack

AircrackDS has the ability to crack 64 and 128 bit WEP keys in a file named ptw.cap on the root of your memory card. The DS has a 67Mhz and a 33Mhz CPU, not the best for cracking. This program uses the PTW method to find keys. And since the DS cannot save wifi captures to a file, the cap file must come from another computer (which could do the cracking much faster than the DS can) This is more of a proof of concept than actually practical, but still cool none the less.

Aircrack on the DS

Reference: http://forum.gbadev.org/viewtopic.php?t=13536

DSLinux

Yes, I know this is a fifth program, and it does not have much of any wifi hacking abilities, but is it so useful I felt it deserves a good mention here. DSLinux is a (small) Linux distro for the Nintendo DS, for the most part it is CLI only, but it can browse the web via links, play music, and it makes a great SSH terminal (see a good guide on how to use screen HERE).

DSLinux

Main site: http://www.dslinux.org Downloads: http://kineox.free.fr/DS/

You can download the first four programs discussed Here


Use EventGhost to Make a XBMC Hulu and Boxee HTPC

The PC

I wanted a HTPC that I could use to play anything, and that could do anything. And since it was going to be hooked up to a big TV, it might as well be powerful enough to play some modern games on the big screen. I chose to use a relatively new computer (Core 2 Duo 2Ghz, Nvidia GeForce GT 220) and run Windows 7. My previous HTPC ran Linux, but with a powerful enough computer, the ability to play games on the HTPC made me move to Windows.

The Three HTPC pieces

I find that XBMCHulu Desktop, and Boxee are all essential parts of a well rounded Home Theater PC (HTPC). XMBC Is great for managing and playing back all of your local media. Hulu Desktop is the complete solution to play anything from Hulu on the big screen. And Boxee does a great job of playing back other online media, such as The Daily ShowPandora, etc. However these three media center programs do not play nice together. There are some small hacks that can make maybe two get along, but not a complete solution.

The Glue

To control all three programs I use EventGhost. EventGhost is a Windows automation tool which can preform a set of actions based on some user input, Usually a key-press, remote control, or other such device. I was lucky enough to have a HP remote control and USB IR sensor from a laptop I had. pictured below:

HP MCE USB IR Remote

Windows 7 automatically recognized the driver for the remote and with the MCE Remote plugin I was able to have EventGhost use it as an input device. I set EventGhost to capture all of the remote’s input and unregister it as a HID device. This stops windows from acting on the remote and gives EventGhost complete control over it.

Next I started creating my EventGhost profile. I chose a button to launch each of the HTPC apps previously mentioned. When pressed, the action for the button would kill any/all running HTPC apps and then start the app that I assigned to the button. This allows me to start any of the apps from the remote and switch between them easily. I also assigned a fourth button that would just kill them all, bringing me to the windows desktop. I assigned the D-PAD and OK buttons to the arrow keys and enter key. That takes care of most of the universal buttons that should apply across all of the programs. Now I went of to the program specific stuff. Hulu Desktop does not need much else or accept any other keyboard shortcuts, but Boxee and XBMC share a few. The next buttons I mapped to the remote are [Backspace], I, [Space], P, X, [Period], [Comma], F, R, H, [Tab], and M. Refer to the Program’s site to see what each one does. I also added a few extra actions for raising and lowering the volume, ejecting the drive tray, and powering off the computer.

I also made a toggle button that would change the D-Pad and OK button from arrow keys and enter to mouse movement and left click. You can download my EventGhost config file at the end of this article. Below is what my configured EventGhost looks like:

EventGhost MCE HTPC Configuration

By now the HTPC setup should be working. You should be able to control and switch between Boxee, XBMC, and Hulu desktop all from your remote. Just remember to make EventGhost start when windows does, this can be easily done by placing a shortcut to EventGhost in your User’s startup folder.

An Extra Surprise

After using this method for a while, I discovered that the MCE remote would detect my TV’s remote control (Pictured below). I could tell because the USB sensor would light up red (showing that it received a signal) when I pressed a button on the TV remote. And low and behold, EventGhost could detect the signal too!

Toshiba TV Remote

This Toshiba remote is also programmable, meaning that it has the ability to also control your VCR, DVD player, etc. I went through all of the preset codes it can use (by entering them all manually and testing them) and found the one that the USB IR sensor would detect the most buttons on. For most, only a few worked, and some none did. Oddly enough the code “000″ had almost all the buttons working. So I went through all the actions in EventGhost and reassigned them to a button on my TV’s remote. This allows me to control both my TV and HTPC from the same remote. All I need to do is switch the Mode/Device at the bottom of the remote to change which device I am controlling.

As promised: My EventGhost Config File


Build Your Own Car Power Inverter

A car inverter will take the 12 volts DC from your car; usually from your cigarette lighter and turn it into 110 volts AC, which is what you get out of your home power outlets. This allows you to plug household electronics into your car. the most common would probably be your laptop. Home UPS systems do the same thing, except instead of using a car outlet they use a 12 volt battery. I used a old home UPS system I had laying around that had a bad battery. (We don’t use the battery in this mod)

Preparing the UPS

Here is the UPS before any modifications:

Only half of the outlets on the device are given power from the UPS system, the rest act as a regular surge strip. The first thing I did was rewire the “surge” outlets to be wired into the UPS power so that all of the outlets would be provided power from the UPS system.

Next I took a car plug adapter I had lying around and conected it to the battery termiinals after removing the battery.

Testing

The UPS system was working and outputting ~106 volts AC from a car’s 12 volts outlet. Here you can see it in action with my meter and a wireless router.

This worked great, but the UPS has a buzzer in it which stayed on. The purpose of this buzzer was to notify you that your power is out and that you are on battery power. However it serves us no purpose and is just really annoying. I fixed it by unsoldering the buzzer from the main circuit board.

Some Final Modifications

In addition to movie the buzzer, I also wanted to make the device smaller as half of it is empty space due to the lack of a battery.

I started my moving two of the LEDs that are on the batter end over to the power switch. I moved just the Power and Overload LEDs, the rest served no use for an inverter.

I used a pipe saw to cut of the battery compartment, there was already a divider on the inside that would now act as the outside wall on that end.

This ups works perfectly as a power inverter. I have used it on several road trips just fine, And because it was intended to be a computer UPS, it can power 350 watts, which is much more than your average car inverter.


N810 as Computer GPS

This guide will tell you how to let a windows computer make use of your N810′s GPS as if it was its own. While the Nokia N810 does not have the best GPS in the world it is still better than no GPS. On a recent road trip I wanted a way to visualize my trip route on a more powerful device than my N810′s 400Mhz possessor and Maemo Mapper. I wanted the full use of my laptop,Google Earth and the internet.

Preparing The Tablet

The built in GPS software does not allow us do do anything advanced like this. We will be using Minigpsd as a replacement for the built in GPS interface software. Minigpsd allows for many more advanced options for the GPS, and may even assist in getting locks faster. Install Minigpsd from the above link. After the installation is complete open up the settings and click the “Advanced” button. Here you will be able to see and set the ports Minigpsd communicates on. You can either leave them at their defaults or change them however you see fit. Below is a screenshot of my configuration.

N810 Minigpsd setup

Now you need to network the Tablet and your Computer. In my case (On a road trip) I was unable to have an access point around, especially in a moving car. So I used an Ad-Hoc Wireless network. But you can use any method you want, including Bluetooth Pan or over your cellular network. I will not go into how to set this up here.

Preparing The Computer

Assuming that your computer is now networked to your N810 you will need software than can take the GPS data from the N810 over the network and bring it to the computer in a form it can use. The best software that I could find that does this isHW Group’s Virtual Serial Port. This software will take the GPS data and make a virtual serial port. From your computer’s point of view it will think that there is a serial GPS attached to it.

Simply start the virtual serial port software up and create a new virtual serial port. It will need an IP address and port. the IP is the IP of your tablet and the port is the “gps direct” port. n the above example is it 22947. Once the port is created make sure your N810 is on and pingable from your computer, and GPSD is running.

Testing It Out

Your computer should now see your N810 as a RAW serial GPS device. To test it out install some GPS aware software. I usedGoogle Earth.

On Google Earth open Tools -> GPS -> Realtime you should see the following:

Google Earth NMEA GPS

If you want to start tracking of the N810, click start. You can change the frequency of the position updates by changing the “Polling interval”.

An alternate method of setting this up without the use of any serial-port emulator on the computer is to use Google Earth’s Network Link function. This will allow Google Earth to look on the N810 for a kml file containing its current longitude and latitude, and use that instead. This KML file can be found on GPSD’s internal web server. On the above example we can see I have it set to run on port 8888. Below is my example configuration:

Google Earth Network Link

I suggest you uncheck “Allow this folder to be expanded” because this file will only contain one updating set of points. also, if you want to use this for real time tracking set the “Time-Based Refresh” to Periodically, and the number of seconds you want between updates. the lower the more smooth the movement will appear.

This concept should work with any GPSD compatible device, including other computers and some modern cell phones. And is in now way limited to Google Earth. I have also tested it with NetStumbler and inSSIDer.


HTC Incredible Video Out

I recently got a HTC Incredible to replace my aging LG Chocolate. One feature of the Incredible was video out. Specifically the ability to output composite video to a TV. The cable was first demoed by WireFly here: http://www.youtube.com/watch?v=eJyt463AoOA And since then threads like these have started trying to hunt down the cable. And it looks like one day it may be sold Here or Here. But for the time being this cable is not being sold anywhere, and there is a rumor that it may never be commercially sold.

Luckily smokeynerd over at XDA Developers made a cable for himself and got the pinouts of the extra 7 pins in the Incredible’s Micro-USB port. See this thread: http://forum.xda-developers.com/showthread.php?p=6647344. With this information I set out to make my own cable. My first attempt was just to verify that it worked, and it was a success. I used alligator clips and needles to make the connection to the video out and ground. But this was not a practical solution because I needed to hold the needles in just the right place so that they would make contact.

First video out cable

Now that I knew that it worked I set out to find something a little more practical. I found a ribbon cable that was just the right size and had the correct pin alignment in an old laptop, (By old I mean it was so old it used the same processor as a desktop, think under 100Mhz). Without thinking twice I scrapped the laptop and used the cable. This ribbon cable was not enough on its own, I also used a standard micro-usb cable to hold it in place, which also allowed the Incredible to charge/sync while the video out is in use. I used two alligator clips much like I did the first time to make the connections to the TV. Below you can see the ribbon cable and micro-USB.

Ribbion cable

Here is a video of the final result:

It works, but I will still be looking into improving it, specifically removing the need for alligator clips. I also noticed that a few pixels are being cut off. This is not a limitation of my cable, this is probably software related, but could possibly have something to do with the Incredible’s video out hardware. When In landscape mode about 5 pixels are missing from the left and when in portrait, both the top and bottom are being cut off. There are also bars on the TV (At least on mine) that go around the entire image, reducing the Incredible’s viewing aria. I was also unable to get the audio to work via this connector, and the Incredible disables its speaker when using video out, however the headphone output still works.

UPDATE: I was able to fix the missing pixels and bars by adjusting my TV’s “picture size”. But I need to re-adjust it every time it switched from landscape to portrait or vise-versa. Hopefully this is just a problem with this particular TV. Below you can see the Phone’s screen without any bars or missing pixels on my TV.

More To Come Soon

Links


Building a PXE Server

PXE is a method for booting an operating system over a network, it stands for Pre Executable environment. Here I will show you how to build a PXE server to boot and or install operating systems over your network.

Installing the server OS

I made this server inside vmware, however the steps are the same if you are using a different virtual machine server or a physical machine. I used Debian 5.0 and used the netinstall iso. Since we will only be needing a bare debian install and just a few extra packages there is no need to download/install the entire OS.

Once you boot the installer follow all the installation prompts and enter the values that apply to you (language/timezone/password/etc). When taksel rins I would recommend unselecting all the options to get the smallest install possible. tasksel in debain

After this the installation will finish, the computer will reboot and you will be presented with a login prompt.

Installing and Setting up the required Services

Now that you have a fresh install of debian install the required packages

apt-get install tftpd-hpa dhcp3-server lftp

This will install the tfp server and a dhcp server. the two programs needed to load files over pxe. Next we need to configure the network to be static. edit /etc/network/interfaces and change the network configuration to something like this:

iface eth1 inet static
address 192.168.1.6
netmask 255.255.255.0
gateway 192.168.1.1

Now bring back up the network interface with ifdown eth0 ifup eth0 to have the new settings take affect.

Next we want to edit /etc/dhcp3/dhcpd.conf. this is the configuration file for the dhcp server. You can look at the default file to see how it is setup, but we don’t need it. replace it with:

allow booting;
allow bootp;

option domain-name-servers 192.168.1.1;
default-lease-time 86400;
max-lease-time 604800;
authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
filename "pxelinux.0";
next-server 192.168.1.6;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
}

This will configure your dhcp server to hand out addresses between 192.168.1.100-200, use a router of 192.168.1.1. And if the dhcp client asks the dhcp server for boot information it will tell it to load a file named pxelinux.0 from 192.168.1.6, which is our server. DHCP is now setup.

Now we need to edit the tftp settings. Edit /etc/default/tftpd-hpa. Change the RUN_DAMON to yes and change the options directory to /tftp, save and close the file. Noe run “mkdir -p /tftp” to create our tftp folder. this will be the server root.

Now start the PXE server with:

/etc/init.d/dhcp3-server start
/etc/init.d/tftpd-hpa start

Setting up the PXE tftp folder

in the root of the tftp folder we need to have pxelinux.0. this is the file that our dhcp server tells the client to download. You can download the latest version from here: http://www.kernel.org/pub/linux/utils/boot/syslinux/ you will need pxelinux.0 found in the core folder of the zip. Place pxelinux.0 in the /tftp folder. Next create a pxelinux.cfg folder inside /tftp. And inside the pxelinux.cfg folder create a default file. This file will contain the boot information for clients if there is not a file that matched their MAC address. If there is one it would be in the pxelinux.cfg folder. Inside of default put:

DISPLAY boot.txt

DEFAULT debian_install

LABEL debian_installl
kernel debian/etch/i386/linux
append vga=normal initrd=debian/lenny/i386/initrd.gz  --

LABEL memtest
kernel memdisk
append initrd=memtest.img  --

LABEL DSL
kernel dsl/linux24
append ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=dsl/minirt24.gz nomce noapic quiet BOOT_IMAGE=knoppix  --

PROMPT 1
TIMEOUT 0

And now create a boot.txt in your /tftpd folder with the following contents:

=PXE Boot Menu=
+++++++++++++++
options are:

debian_install
DSL
memtest

Now the boot.txt will be displayed allowing you to enter a label that is defined in default and it will boot that kernel with the given options. You can edit default and boot.txt however you like. In the examples iv given you have the option to install debian, boot memtest, or boot damn small linux. However we are still missing a vital part of the pxe server. We need the actual boot files. You can download the debian files HERE The DSL and memtest files can be found on their appropriate websites.

Each boot option should go in its own folder inside the /tftp folder. In the above example debian is in the debian folder, dsl is in dsl. However because memtest is only a single file i put it directly in the tftpd root. Remember you must edit the default file to contain the correct boot arguments and kernel for what you are trying to boot.

Happy Network Booting!

PXE from Syslinux


Switch Network Interface in Linux

This guide will tell you how to rename or switch network controller names in Linux. Often when installing Linux the installer will automatically pick the names of the network controllers. And for some reson the order it names them is almost always not the order I want them in. I usually like the primary/onboard card eth0, and all addin cards eth1-n, however the installer often has its own ideas. So this is how to correct it!

First off we need to tell the kernel which name gets associated with which physical card. On Debian based systems the information is in /etc/udev/rules.d/70-persistent-net.rules and on Redhat based systems it is in /etc/sysconfig/network-scripts/ifcfg-ethX. You will need to edit thoes files as root. In each file will be a line for each network controller with its mac address, driver, and name. You want to just edit the name to be what you want. For me that is often just changing eth0 to eth1 and vise versa. When you are done you may save these files.

Next you need to configure the IP information for the controllers. Edit (as root) /etc/network/interfaces. This file contains the IP address settings for each adapter. If you want eth0 to USE DHCP use:

auto eth0
iface eth0 inet dhcp

If you want to settup a static IP address use:

iface eth1 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.1

But obviously change the settings to fit your needs.

Now save that file and apply reboot to apply the changes.

Stack Overflow Question on this

Manual temporary configuration

As you should know ifup ethX turns on the network interface and ifdown ethX turns it off, but these only work if the above interfaces file is configured correctly. If the file is configured incorrectly or you want to temporarily use a different configuration you can do so with these commands. Note that the adapter must be in the “down” state before issuing these. you can do this by running “idfown ethX”

ifconfig [device] [static ip ] netmask [network mask] gateway [router ip] up

Or

ifconfig [device] dhcp start

This will bring your current network adapter up with a temporary configuration which will be cleared next time the adapter is brought down (either manually or by a reboot)