Saturday, April 7, 2018

linux - How to Create a network connection between host and guest using static ip in Oracle Virtual Box


In host I am using Scientific Linux 6.4


In guest I am using CentOS 6.4


Oracle Virtual Box Version 4.2.18 r88780


I want a create a network between host and guest machine using static ip so in Virtual Box I selected Host-only Adapter


enter image description here


In base system it created a new interface called vboxnet0



vboxnet0 Link encap:Ethernet HWaddr 0A:00:27:00:00:00
inet addr:192.168.56.1 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:468 (468.0 b)

After starting guest os I tried ping command to ping my host machine, it was not pinging, this is the output.



[root@localhost ~]# ping 192.168.56.1
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
From 192.168.56.2 icmp_seq=1 Destination Host Unreachable
From 192.168.56.2 icmp_seq=2 Destination Host Unreachable
From 192.168.56.2 icmp_seq=3 Destination Host Unreachable
^C
--- 192.168.56.1 ping statistics ---
6 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4658ms
pipe 3

In guest machine for which interface I should set static ip ? for eth0 I set the static ip ie; 192.168.56.3 still it's not pinging.


Answer



Finally I got the solution.


While typing ifconfig eth0 it was showing the ip address.



[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:1E:EC:95:18:66
inet addr:192.168.56.7 Bcast:192.168.56.255 Mask:255.255.255.0
UP 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:19

In /etc/sysconfig/network-scripts/ifcfg-eth0 file also it was showing ip address.



.
.
IPADDR=192.168.56.7
NETMASK=255.255.255.0
.
.

Even it was pinging the ip also.



[root@localhost ~]# ping 192.168.56.7
PING 192.168.56.7 (192.168.56.7) 56(84) bytes of data.
64 bytes from 192.168.56.7: icmp_seq=1 ttl=64 time=0.098 ms
64 bytes from 192.168.56.7: icmp_seq=2 ttl=64 time=0.080 ms
64 bytes from 192.168.56.7: icmp_seq=3 ttl=64 time=0.087 ms
^C
--- 192.168.56.7 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2032ms
rtt min/avg/max/mdev = 0.080/0.088/0.098/0.010 ms

Here I got confused, I thought that it's pinging right then my eth0 interface is working. This is the main mistake I did.


Today I tried this command



[root@localhost ~]# /etc/init.d/network restart
Shutting down interface eth0: Error: Device 'eth0' (/org/freedesktop/NetworkManager/Devices/0) disconnecting failed: This device is not active
[FAILED]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: RTNETLINK answers: File exists

It was showing this This device is not active . Then I got the reason why its not working. After that I edited /etc/sysconfig/network-scripts/ifcfg-eth0 file with only this content and deleted all the other lines.



DEVICE=eth0
BOOTPROTO=none
HWADDR=AA:BB:BB:DD:EE:FF
NM_CONTROLLED=no
ONBOOT=yes
IPADDR=192.168.56.7
NETMASK=255.255.255.0

After that I restated the network service, tried ping command and its started to ping my guest machine that is 192.168.56.9.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...