Sunday, November 25, 2012

Change your Network Card MAC Address on Ubuntu

There are a lot of reasons you might want to manually set your MAC address for your network card. I won’t ask you what your reason is.
To change this setting, we’ll need to edit the /etc/network/interfaces file. You can choose to use a different editor if you’d like.
sudo gedit /etc/network/interfaces
You should see the line for your network interface, which is usually eth0. If you have dhcp enabled, it will look like this:
auto eth0
iface eth0 inet dhcp
Just add another line below it to make it look something like this:
auto eth0
iface eth0 inet dhcp
       hwaddress ether 01:02:03:04:05:06
Obviously you would want to choose something else for the MAC address, but it needs to be in the same format.
sudo /etc/init.d/networking restart
You will need to restart networking or reboot to take effect.

Change the GRUB Menu Timeout on Ubuntu

When your Ubuntu system boots, you will see the GRUB menu if you hit the Esc key, or if you’ve enabled the menu to show by default. The only issue with this is that the default timeout is only 3 seconds. You may want to increase this amount… or you may even want to decrease it. Either one is simple.
Open up the /boot/grub/menu.lst file in your favorite text editor. I’m using gedit:
sudo gedit /boot/grub/menu.lst
Now find the section that looks like this:
## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 3
The timeout value is in seconds. Save the file, and when you reboot you will have that many seconds to choose the menu item you want.

Change the DHCP IP Address Range for VMware NAT

VMware Workstation includes a network utility that allows you to manage the virtual networks. Typically virtual machines will use NAT (Network Address Translation) to automatically assign a virtual IP address that hides behind your host address, but the default range of 192.168.200.0/24 may not work for everybody.
You can change this address range to anything you like easily. Note that you should not have virtual machines running during this.
First open the Manage Virtual Networks start menu item:

Click the Host Virtual Network Mapping tab, and then click the arrow button next to the VMnet8 dropdown box. VMnet8 is the default NAT adapter for VMware.

Choose the Subnet option, and you will see a dialog where you can change the network range:

Once you have changed the network here, you can click the OK or Apply buttons, and after a few seconds it will update.

Change SSH Welcome Banner on Ubuntu

Every time I connect to my Ubuntu development server through my ssh client, I receive the same message and I’m getting tired of seeing it, so I decided to change the message to something else.
Here’s the message that I get every time:
Linux superfast 2.6.20-16-generic #2 SMP Thu Jun 7 19:00:28 UTC 2007 x86_64
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
Last login: Mon Aug 13 01:05:46 2007 from ipaddress removed
geek@superfast:~$
Changing this message requires editing two different files. The first three sections can be modified by editing the following file:
/etc/motd
This file contains the linux build number as well as the Ubuntu warranty message. I don’t find this particularly useful, so I removed all of it and replaced it with my own message.
To disable the last login message (which I don’t recommend doing), you will need to edit the following file in sudo mode:
/etc/ssh/sshd_config
Find this line in the file and change the yes to no as shown:
PrintLastLog no
Now when you login, you’ll get a blank prompt, although I wouldn’t necessarily recommend it because it’s useful to see the last login to the system for security reasons. This is my prompt now:
This is a superfast system. Please max out the cpu accordingly.
Last login: Mon Aug 13 01:24:14 2007 from ipaddress removed
geek@superfast:~$
Linux is really great.

Change or set the MySQL root password

For every database, you should set the root or sa passwords to something other than the default, unless you want to get hacked. For mysql, the system administrator user is called root. You will use the mysqladmin utility from a command line to set the new password. Notice that there are two commands to be run.
Syntax:
mysqladmin -u root password “newpassword”
mysqladmin -u root -h host_name password “newpassword”
Example:
mysqladmin -u root password ws8dr8as3
mysqladmin -u root -h localhost password ws8dr8as3
You will also want to restart the database server after running this command
sudo /etc/init.d/mysql restart

Boot from a USB drive even if your BIOS Won’t Let You

You’ve always got a trusty bootable USB flash drive with you to solve computer problems, but what if a PC’s BIOS won’t let you boot from USB? We’ll show you how to make a CD or floppy disk that will let you boot from your USB drive.
sshot-1
This boot menu, like many created before USB drives became cheap and commonplace, does not include an option to boot from a USB drive.
A piece of freeware called PLoP Boot Manager solves this problem, offering an image that can burned to a CD or put on a floppy disk, and enables you to boot to a variety of devices, including USB drives.
Put PLoP on a CD
PLoP comes as a zip file, which includes a variety of files. To put PLoP on a CD, you will need either plpbt.iso or plpbtnoemul.iso from that zip file. Either disc image should work on most computers, though if in doubt plpbtnoemul.iso should work “everywhere,” according to the readme included with PLoP Boot Manager.
Burn plpbtnoemul.iso or plpbt.iso to a CD and then skip to the “booting PLoP Boot Manager” section.
Put PLoP on a Floppy Disk
If your computer is old enough to still have a floppy drive, then you will need to put the contents of the plpbt.img image file found in PLoP’s zip file on a floppy disk.
To do this, we’ll use a freeware utility called RawWrite for Windows.
sshot-6
We aren’t fortunate enough to have a floppy drive installed, but if you do it should be listed in the Floppy drive drop-down box. Select your floppy drive, then click on the “…” button and browse to plpbt.img. Press the Write button to write PLoP boot manager to your floppy disk.
sshot-7
Booting PLoP Boot Manager
To boot PLoP, you will need to have your CD or floppy drive boot with higher precedence than your hard drive. In many cases, especially with floppy disks, this is done by default.
If the CD or floppy drive is not set to boot first, then you will need to access your BIOS’s boot menu, or the setup menu. The exact steps to do this vary depending on your BIOS – to get a detailed description of the process, search for your motherboard’s manual (or your laptop’s manual if you’re working with a laptop).
In general, however, as the computer boots up, some important keyboard strokes are noted somewhere prominent on the screen. In our case, they are at the bottom of the screen.
sshot-18
Press Escape to bring up the Boot Menu. Previously, we burned a CD with PLoP Boot Manager on it, so we will select the CD-ROM Drive option and hit Enter.
sshot-2
If your BIOS does not have a Boot Menu, then you will need to access the Setup menu and change the boot order to give the floppy disk or CD-ROM Drive higher precedence than the hard drive. Usually this setting is found in the “Boot” or “Advanced” section of the Setup menu.
sshot-17
If done correctly, PLoP Boot Manager will load up, giving a number of boot options.
sshot-3
Highlight USB and press Enter.
sshot-4
PLoP begins loading from the USB drive.
sshot-5
Despite our BIOS not having the option, we’re now booting using the USB drive, which in our case holds an Ubuntu Live CD!
sshot-8
This is a pretty geeky way to get your PC to boot from a USB…provided your computer still has a floppy drive. Of course if your BIOS won’t boot from a USB it probably has one…or you really need to update it.

Backup MySQL Database to a file

Backing up your database is a very important system administration task, and should generally be run from a cron job at scheduled intervals. We will use the mysqldump utility included with mysql to dump the contents of the database to a text file that can be easily re-imported.
Syntax:
mysqldump -h localhost -u root -pmypassword databasename > dumpfile.sql
Example:
mysqldump -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql
This will give you a text file containing all the commands required to recreate the database.