Sabtu, 30 Juni 2012

Create Virtual Interface in Your Ubuntu Machine

Im trying now to get my machine to run 2 virtual hosts in Apache. This is part of my favor to my friends actually.

So, first thing first, I need to create virtual interface to my loopback. Manually, I will type this in:

yuvi@yuvi:~$ sudo ifconfig lo:0 192.168.1.1 255.255.255.0 up
[sudo] password for yuvi: 
SIOCSIFADDR: Invalid argument
yuvi@yuvi:~$ ifconfig
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:336 errors:0 dropped:0 overruns:0 frame:0
          TX packets:336 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:30943 (30.9 KB)  TX bytes:30943 (30.9 KB)

lo:0      Link encap:Local Loopback  
          inet addr:192.168.1.1  Mask:255.255.255.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1

yuvi@yuvi:~$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_req=1 ttl=64 time=0.045 ms
64 bytes from 192.168.1.1: icmp_req=2 ttl=64 time=0.030 ms
^C
--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.030/0.037/0.045/0.009 ms

Can see now it's up, i can ping successfully. 

Problem is, when I reboot, it's not there anymore. So, to make this permanent, have tried adding in 

yuvi@yuvi:~$ more /etc/network/interfaces 
auto lo
iface lo inet loopback

#Virtual Interface
auto lo:0
iface lo:0 inet loopback
address 192.168.1.1
netmask 255.255.255.0

But same result, it still doesnt go up. My boot.log and syslog didnt tell me anything, so ... I think I can go with crontab:

yuvi@yuvi:~$ sudo crontab -l
@reboot ifconfig lo:0 192.168.1.1 255.255.255.0 up

And ..... bingo, it still doesnt work, dont know why ... please tell me why if anyone knows ...

So, move to other alternative, create an rc script:

root@yuvi:/etc/init.d# more IfUplo 
#!/bin/bash
ifconfig lo:0 192.168.1.1 255.255.255.0 up
echo "Virtual Interface Loopback Up"

root@yuvi:/etc/init.d# ls -ls IfUplo 
4 -rwxrwxrwx 1 root root 93 2012-06-30 09:20 IfUplo

root@yuvi:/etc/init.d# update-rc.d IfUplo defaults
root@yuvi:/etc/init.d# locate IfUplo 
/etc/init.d/IfUplo
/etc/rc0.d/K20IfUplo
/etc/rc1.d/K20IfUplo
/etc/rc2.d/S20IfUplo
/etc/rc3.d/S20IfUplo
/etc/rc4.d/S20IfUplo
/etc/rc5.d/S20IfUplo
/etc/rc6.d/K20IfUplo
/var/lib/update-rc.d/IfUplo

Please bear in mind that this script does give me an error of not complying with LSB ... small script, doesnt really matter. So there, it creates links for me in all rcs directories:

Reboot and ..... yesss it works.

Tidak ada komentar: