in CentOS

How to configure ssh access to virtualbox guest under NAT mode

Just quick note for my own 🙂

I need to ssh to my CentOS 6.6 box that run under Virtualbox with these steps :

1. NAT

Virtualbox will create private network using these address (10.0.2.xxx). Just set eth0 configuration to DHCP and everything will be set.

vbox_centos1

2.  Port forwarding setup to port 2222

Click Setting -> Network -> Port Forwarding

vbox_centos2

 

3. Test ssh connection

ssh [email protected] -p 2222
The authenticity of host ‘[127.0.1.1]:2222 ([127.0.1.1]:2222)’ can’t be established.
RSA key fingerprint is ee:81:d0:da:7e:b4:fe:bc:cd:d7:93:e0:fc:c3:63:80.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘[127.0.1.1]:2222’ (RSA) to the list of known hosts.

[email protected]’s password:
Last login: Tue Jun 2 10:57:58 2015
[[email protected] ~]#

[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:1F:5E:0D
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe1f:5e0d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6410 errors:0 dropped:0 overruns:0 frame:0
TX packets:4175 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9148159 (8.7 MiB) TX bytes:234084 (228.5 KiB)

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:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:600 (600.0 b) TX bytes:600 (600.0 b)

Of course the connection work on ‘temporary’ ip address. To make it permanent, editing /etc/sysconfig/ifcfg-eth0 needed to set ip address static.