Issue
After deploying a virtual appliance inside VirtualBox, the guest has a DHCP IP address and everything works fine. The problem is that I need to have this VM on a static IP address.
This VM is the latest Bitnami Postgres, running on Debian 11.
When performing ifconfig
, I get this for the relevant network interface :
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.196 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::a00:27ff:fe5e:6c9 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:5e:06:c9 txqueuelen 1000 (Ethernet)
RX packets 1431 bytes 113648 (110.9 KiB)
RX errors 0 dropped 244 overruns 0 frame 0
TX packets 306 bytes 22928 (22.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19 base 0xd000
I have tried following the vendor's recommended steps to assign a static IP address, namely by adding the file /etc/systemd/network/25-wired.network
, however this does not work :
[Match]
Name=enp0s3
[Network]
Address=192.168.2.52
Gateway=192.168.1.1
As indicated by the DHCP result, the subnet is 255.255.255.0
(or 192.168.2.52/24
) so I changed the config file to :
[Match]
Name=enp0s3
[Network]
Address=192.168.2.52/24
Gateway=192.168.1.1
But then it complains that the Gateway
is not on the same subnet! Changing it to :
[Match]
Name=enp0s3
[Network]
Address=192.168.2.52/16
Gateway=192.168.1.1
yields no error when restarting the network service, however routing is broken and nothing is accessible; the guest can't ping any machine, and no machine can ping the guest!
I tried adding various sections, like Route]
, [Address]
, etc. I am at a loss.
Solution
You define your subnet to be at 192.168.2.0/24
, witch excludes the possibility to include your gateway at 192.168.1.1
!
The correction done by the system is correct: Indeed, the mask for that IP/Gateway configuration is 16
, or netmask>24
.
You should review your desired network configuration, and remember that the netmask 24 will define a minimum subnet address of x.y.z.1
-> x.y.z.254
. In both cases x.y.z
remain the same.
Your gateway needs to be inside of the subnet. If you really want to use the IP 192.168.2.196
with the gateway at 192.168.1.1
, try the netmask 23
. That being said: I doubt that your gateway uses the netmask 23
(seems a standard router configuration to me).
Answered By - ricard0 Answer Checked By - Gilberto Lyons (WPSolving Admin)