Friday, January 24, 2014

Forget root password on ubuntu

Use a Ubuntu disk, and boot into the rescue mode. Choose to run a shell. Then you can gain the root privilege.

Network Configuration on Ubuntu

Sample configuration file:

@sr2s17:~$ cat /etc/network/interfaces 
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

auto eth2
iface eth2 inet static
address 192.168.0.37

netmask 255.255.255.0


I use interface eth0 as the external network and eth2 as the internal network. 

After you install Ubuntu, the interfaces may not be up. Although you can use ethtool to detect if the interfaces are physically connected by cables, This approach is not accurate on Ubuntu (works on CentOS). 

For example, I know there are six interfaces on my server
eth0 and eth1 are on a broadcom network card, and eth2, 3, 4, 5 are on a Intel network card. 
I plugged the Ethernet cable to the eth2 interface, so I just need to write the script into /etc/network/interfaces, which help me to enable the eth2. Next, I run a $ /etc/init.d/networking restart

Thursday, January 23, 2014

NFS on ubuntu

root@sr2s17:/home/fengwei# mount -a
mount: unknown filesystem type 'nfs4'

root@sr2s17:/home/fengwei# apt-get install nfs-common

https://help.ubuntu.com/community/SettingUpNFSHowTo

Fix: sudo: setresuid(ROOT_UID, ROOT_UID, ROOT_UID): Operation not permitted

This is a known bug for Ubuntu 12.04 with LDAP

It is caused by libgcrypt in GnuTLS that used by LDAP for SSL connections.

Solution:
Use libnettle instead of libgcrypt, and recompile gnutls26

Since you don't have sudo, you can use Ubuntu disk boot into rescue mode.
1) create the root user
or
2) gain sudo by disabling the ldap  $ mv /etc/ldap.conf /etc/ldap.conf.backup; $ reboot

After you have the root privilege, boot your machine into normal disk.  The following commands disabled ldap when fixing this bug.

Step 1. Install necessary packages

sudo apt-get install libgmp-dev devscripts 
sudo apt-get build-dep libgnutls26

Step 2. Download and install nettle

$ wget http://www.lysator.liu.se/~nisse/archive/nettle-2.1.tar.gz 
$ tar zxvf nettle-2.1.tar.gz 
$ cd nettle-2.1 
$./configure --with-gmp 
$ make 
$ sudo make install
$ sudo reboot ( I have a compiling issue with gnutls26 if don't reboot here)

Step 3. Compile and build gnutls26

$ sudo apt-get source gnutls26
$ cd gnutls26-2.12.14
$ sudo vim debian/rules
remove --with-libgcrypt

$ sudo debuild -i -uc -us -b 
$ cd .. 
$ dpkg -i libgnutls26_2.12.14*.deb

Source: 
https://jeroenvda.eu/2012/05/03/cannot-setuid-after-ubuntu-12-04lts-upgrade-when-using-ldap-accounts/
http://askubuntu.com/questions/106642/how-to-fix-sudo-setreuidroot-uid-user-uid-operation-not-permitted-error

Create a local root user on Ubuntu

$ sudo passwd root

enter the password. if you want to become a root, then you can just type $ su

It aways good idea to create one, because the sudo may not be functional, such as this bug:

http://askubuntu.com/questions/106642/how-to-fix-sudo-setreuidroot-uid-user-uid-operation-not-permitted-error

Monday, January 13, 2014

Configure the hostname in CentOS

Test a hostname if working:
nfslookup HOSTNAME
or
nfslookup IP_ADDRESS

to see if there is an entry in the DNS server

First, you need to have a correct network script in /etc/sysconfig/network-script/ifcfg-eth4

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 


DEVICE=eth4                                   //device name
HWADDR=00:26:B9:38:4C:23            // mac address 
TYPE=Ethernet                         
ONBOOT=yes                                  // automatically connected after bootup
NM_CONTROLLED=no                     // does not use Network Manager, use ifcfg-eth4 script
BOOTPROTO=dhcp                         // use DHCP
DHCP_HOSTNAME=sr2s18              // configure DHCP hostname

PEERDNS=yes                                //Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default


Then, configure the hostname:

http://www.rackspace.com/knowledge_center/article/centos-hostname-change

1. set /etc/sysconfig/network

[root@sr2s16 ~]# cat /etc/sysconfig/network
NETWORKING_IPV6=no
HOSTNAME=sr2s16.example.com

NETWORKING=yes

2. configre /etc/hosts

[root@sr2s16 ~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
129.174.114.142 sr2s16.example.com sr2s16
::1 sr2s16.example.com sr2s16

192.168.0.36 sr2s16.example.com sr2s16


3. restart network

$ service network restart









Friday, January 10, 2014

network configuration sample on Cent OS

External network interface using dhcp: /etc/sysconfig/network-script/ifcfg-eth4

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 

DEVICE=eth4
HWADDR=00:26:B9:38:4C:23
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

Internal network interface using static IP: /etc/sysconfig/network-script/ifcfg-eth0

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=00:1B:21:44:96:10
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.38
BROADCAST=192.158.0.25
NETMASK=255.255.255.0
NAME=eth0