How to get a hostname for a jail

I use dnsmasq as a dhcp server and am using IOCAGE to manage jails, but have no idea how IP address are allocated or ir they can be pre-configured in some way, but would like to know whether there is any way to assign a hostname to a jail.

Can anyone tell me?
 
am using IOCAGE to manage jails
Why don't you consult the sysutils/iocage documentation (no offense, but it's not the first time you don't)? If I'm unfamiliar with a program, I look in the documentation, if available, online, and local installed manuals.

It took me as a non-iocage-user a few seconds to find the answers you seek by looking into the iocage online documentation and manual page (iocage(8)).

have no idea how IP address are allocated or ir they can be pre-configured in some way
https://iocage.readthedocs.io/en/latest/networking.html#configuring-network-interfaces .

Networking​

Jails have multiple networking options to better serve a user’s needs.Traditionally, jails have only supported IP alias based networking. Thisis where an IP address is assigned to the host’s interface and then usedby the jail for network communication. This is typically known as“shared IP” based jails.

Another recently developed option is called VNET or sometimes VIMAGE.VNET is a fully virtualized networking stack which is isolated per jail.VNET abstracts virtual network interfaces to jails, which then behave inthe same way as physical interfaces.

By default, iocage does not enable VNET, but users can enable andconfigure VNET for a jail by configuring that jail’s properties usingthe instructions in the Configure a Jail section of thisdocumentation.

The rest of this section shows more depth of the Shared IP andVNET networking options, along with instructions forConfiguring Network Interfaces.

I use dnsmasq as a dhcp server
To create a a jail with a DHCP interface add the dhcp=on property:

# iocage create -r 11.0-RELEASE --name myjail dhcp=on

The dhcp=on property implies creating a VNET virtual network stack and enabling the Berkley Packet Filter. DHCP cannot work without VNET. More information about VNET is available in the VNET(9) FreeBSD manual page.

would like to know whether there is any way to assign a hostname to a jail.

The "hostname" can be the same as the jail name and can be set when the jail is created, for example:
iocage(8)
Code:
EXAMPLES

       Create first jail:

         iocage create -r 11.0-RELEASE -n myjail

Or "hostname" can be changed with the iocage set command:
Code:
#  icoage set host_hostname=<hostname>  myjail
See iocage(8), PROPERTIES.
 
I was looking for a way to assign a hostname at the time of creating the jail, but didn't see it.

Is it possible to use dnsmasq to provide a hostname.

Also with IOCAGE jails, I don't how I can allocate an IP address since there is no MAC address and I don't know how vnet no.s or epair addresses work.

This is an area which is still a large mystery. I'm just grateful that I stumbled across some way of getting IOCAGE jails to work.
 
I was looking for a way to assign a hostname at the time of creating the jail, but didn't see it.
All in the iocage documentation.

Example jail name is hostname:
Code:
iocage create -r 15.1-RELEASE -n myjail

Example jail name and hostname differ:
Code:
iocage create -r 15.1-RELEASE -n myjail host_hostname=<hostname>

Is it possible to use dnsmasq to provide a hostname.
Sure, assuming dnsmasq(8), --dhcp-host, you have to use vnet in iocage jails to get network interface MAC addresses, see "Tips for Configuring VNET":
Force iocage to regenerate the MAC and HW address (e.g.: after cloning a jail). This will cause the MAC and HW addresses to be regenerated when the jail is next started.

# iocage set vnet0_mac=none examplejail

Following example under revision, will post later.
 
Example host "vnet" jail bridge(8) and iocage jail DHCP static IP lease configuration: Host /etc/rc.conf, see handbook "17.5.3. Creating a VNET Jail". Change IP addresses and network interface names accordingly to your lan setup and network devices:
Code:
defaultrouter="192.168.1.1"
cloned_interfaces="bridge0"
ifconfig_bridge0="inet 192.168.1.2/24 addm em0"
ifconfig_em0="up"
service netif restart

iocage new jail "vnet" "dhcp" configuration:
Code:
#  iocage  create  -r 15.1-RELEASE  -n myjail  bpf=1 dhcp=1 vnet=1
See iocage(8) for SUBCOMMANDS and PROPERTIES.

iocage existing jail "vnet" "dhcp" configuration. The bold highlighted is the "ether" MAC address (5a9cfcff3e07).:
Rich (BB code):
# iocage  set  bpf=1  jail1
# iocage  set  dhcp=1  jail1
# iocage  set  vnet=1  jail1

# iocage  start  jail1
# iocage  get  vnet0_mac  jail1
5a9cfcff3e06  5a9cfcff3e07

# iocage  stop  jail1

Configure dhcp-host in /usr/local/etc/dnsmasq.conf:
Rich (BB code):
dhcp-host=5a:9c:fc:ff:3e:07,192.168.1.15,jail1
Restart service: service dnsmasq restart

Start iocage jail:
Rich (BB code):
root@iocage-test:~ # iocage start jail1
No default gateway found for ipv6.
* Starting jail1
  + Started OK
  + Using devfs_ruleset: 1000 (iocage generated default)
  + Configuring VNET OK
  + Using IP options: vnet
  + Starting services OK
  + Executing poststart OK
  + DHCP Address: 192.168.1.15/24
 
  root@iocage-test:~ # iocage list -l
+------+-------+------+-------+------+--------------+-----------------------+-----+----------+----------+
| JID  | NAME  | BOOT | STATE | TYPE |   RELEASE    |          IP4          | IP6 | TEMPLATE | BASEJAIL |
+======+=======+======+=======+======+==============+=======================+=====+==========+==========+
| 8    | jail1 | off  | up    | jail | 15.1-RELEASE | epair0b|192.168.1.15  | -   | -        | no       |
+------+-------+------+-------+------+--------------+-----------------------+-----+----------+----------+

iocage "jail1" jail console:
Rich (BB code):
root@jail1: ~ # ifconfig epair0b
epair0b: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
        options=200019<RXCSUM,VLAN_MTU,VLAN_HWTAGGING,RXCSUM_IPV6>
        ether 5a:9c:fc:ff:3e:07
        hwaddr 58:9c:fc:10:83:fd
        inet 192.168.1.15 netmask 0xffffff00 broadcast 192.168.1.255
        inet6 fe80::589c:fcff:feff:3e07%epair0b prefixlen 64 scopeid 0x6
        groups: epair
        media: Ethernet 10Gbase-T (10Gbase-T <full-duplex>)
        status: active
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
 
Many thanks for the detailed explanation about how to use dnsmasq. I would not have been able to figure it out by reading the docs.
 
One thing I can't figure is, is there any way to get the IP address of the jail returned when executing iocage create $JAIL ?
 
Back
Top