Having trouble with networking inside of a jail

I am using FreeBSD 10, and am having some trouble getting networking inside of a jail going. I have been following this here:
http://www.scottro.net/freebsdjail.html
This is the output of dhclient dc0 inside of the jail:
Code:
# dhclient dc0
Can't create socket
exiting.

Here is /etc/rc.conf.
Code:
hostname="sparkette"
ifconfig_dc0="DHCP"
sshd_enable="YES"
ntpd_enable="YES"
powerd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
jail_enable=YES
jail_list="jordan"
ifconfig_dc0_alias0="inet 192.168.2.20 netmask 255.255.255.0"

Here is /etc/jail.conf.
Code:
jordan {
   path = /jails/jordan;
   mount.devfs;
   devfs_ruleset = 4;
   host.hostname = jordanbsd;
   ip4.addr = 192.168.2.20;
   exec.start = "/bin/sh /etc/rc";
   exec.stop = "/bin/sh /etc/rc.shutdown";
}
ifconfig from outside of the jail produces:
Code:
dc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
   options=80008<VLAN_MTU,LINKSTATE>
   ether 00:04:5a:8a:d5:e6
   inet 192.168.2.20 netmask 0xffffff00 broadcast 192.168.2.255
   inet 192.168.2.19 netmask 0xffffff00 broadcast 192.168.2.255
   nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
   media: Ethernet autoselect (100baseTX <full-duplex>)
   status: active
msk0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
   options=c011a<TXCSUM,VLAN_MTU,VLAN_HWTAGGING,TSO4,VLAN_HWTSO,LINKSTATE>
   ether 00:00:00:00:00:00
   nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
   media: Ethernet autoselect
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
   options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
   inet6 ::1 prefixlen 128
   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
   inet 127.0.0.1 netmask 0xff000000
   nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
Inside of my jail, /etc/rc.conf:
Code:
hostname="jordanbsd"
sshd_enable="YES"
ifconfig_dc0="DHCP"

Here is ifconfig
Code:
dc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
   options=80008<VLAN_MTU,LINKSTATE>
   ether 00:04:5a:8a:d5:e6
   media: Ethernet autoselect (100baseTX <full-duplex>)
   status: active
msk0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
   options=c011a<TXCSUM,VLAN_MTU,VLAN_HWTAGGING,TSO4,VLAN_HWTSO,LINKSTATE>
   ether 00:00:00:00:00:00
   media: Ethernet autoselect
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
   options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
jls:
Code:
# jls
  JID  IP Address  Hostname  Path
  14  192.168.2.20  jordanbsd  /jails/jordan
 
You don't need to run dhclient(8) inside the jail. Additionally you can't as a jail neither has the permissions to change its IP address nor does it have access to the bpf(4) device that dhclient(8) needs to listen for network packets.

The simplest thing you can do is to remove the alias parameter from your /etc/rc.conf and set your jail.conf to assign the IP address when the jail is started. This will assign 192.168.2.20 with a 255.255.255.255 subnet mask which is generally the recommended config (not the 255.255.255.0 mask for an alias IP address).

Code:
ip4.addr = 'dc0|192.168.2.20';
 
This will assign 192.168.2.20 with a 255.255.255.255 subnet mask which is generally the recommended config (not the 255.255.255.0 mask for an alias IP address).

This is no longer the case at least with FreeBSD 10 and probably on FreeBSD 9 too. It is perfectly fine to use the same netmask on the alias addresses as the "main" address uses, I can't find out when exactly this was changed though.
 
Back
Top