How to connect FreeBSD Jail to network

11,590

Solution 1

You'll want to add an entry to /etc/rc.conf to ensure the alias is recreated on reboot. Also, you might consider using ezjail.

Solution 2

For this case, configuring the jail IP as a virtual IP on the interface rl0 via the host fixed it:

#ifconfig rl0 192.168.100.174 netmask 255.255.255.0 alias
Share:
11,590

Related videos on Youtube

Player 2nd
Author by

Player 2nd

Updated on September 18, 2022

Comments

  • Player 2nd
    Player 2nd almost 2 years

    So recently I successfully installed and configured a freebsd jail and I would like to install software within my jail but I cannot connect to the network. I'm trying to setup an apache+php+mysql installation within the jail and have the webserver accessible by users. Here is my rc.conf for the jail.

    ...
    jail_enable="YES"   # Set to NO to disable starting of any jails
    jail_list="mambo2"     # Space separated list of names of jails
    
    jail_mambo2_rootdir="/usr/jails/j01"     # jail's root directory
    jail_mambo2_hostname="mambo2.ug"  # jail's hostname
    jail_mambo2_ip="192.168.100.174"           # jail's IP address
    jail_mambo2_devfs_enable="YES"          # mount devfs in the jail
    jail_mambo2_devfs_ruleset="mambo2_ruleset" # devfs ruleset to apply to jail
    

    here is my jail ifconfig output

    mambo2# ifconfig
    rl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
            options=8<VLAN_MTU>
            ether 00:c1:28:00:48:db
            media: Ethernet autoselect (100baseTX <full-duplex>)
            status: active
    plip0: flags=108810<POINTOPOINT,SIMPLEX,MULTICAST,NEEDSGIANT> metric 0 mtu 1500
    lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    mambo2#
    

    It does not show the IP address I configured within /etc/rc.conf. But, when I list the running jails, it shows the right IP address.

    Here is a list of jails running

    [root@mambo /usr/home/jtumusiime]# jls
    JID  IP Address      Hostname                      Path
    5  192.168.100.174 mambo2.ug                     /usr/jails/j01
    

    I also created a /etc/resolv.conf for nameservers. This was not in existence so I'm not quite sure if it is necessary?

    mambo2# cat /etc/resolv.conf 
    nameserver  192.168.100.251
    nameserver  8.8.8.8
    
    mambo2# 
    

    my host has 4 ip addresses, 3 public and one private: 192.168.100.173

    I tried creating a jail using ezjail and this does not work out.

    [root@mambo /usr/src]# ezjail-admin update -p -i
    Error: Cannot find your copy of the FreeBSD source tree in .
      Consider using 'ezjail-admin install' to create the base jail from an ftp server.
    [root@mambo /usr/src]# 
    

    I have an updated copy of freebsd 7.1 source tree from SVN in /usr/src/

    [root@mambo /usr/src]# svn info
    Path: .
    URL: http://svn.freebsd.org/base/release/7.1.0
    Repository Root: http://svn.freebsd.org/base
    Repository UUID: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
    Revision: 243371
    Node Kind: directory
    Schedule: normal
    Last Changed Author: kensmith
    Last Changed Rev: 186660
    Last Changed Date: 2009-01-01 01:57:14 +0300 (Thu, 01 Jan 2009)
    
    [root@mambo /usr/src]#
    

    and I did

    #make buildworld
    

    while building the first jail i.e mambo2

    Here is an excerpt of ouput of ezjail-admin install

    ...
    221 Goodbye.
    Trying 193.162.146.4...
    Connected to ftp.freebsd.org.
    220 ftp.beastie.tdk.net FTP server (Version 6.00LS) ready.
    331 Guest login ok, send your email address as password.
    230 Guest login ok, access restrictions apply.
    Remote system type is UNIX.
    Using binary mode to transfer files.
    200 Type set to I.
    550 pub/FreeBSD-Archive/old-releases/i386/7.1-RELEASE/base: No such file or directory.
    221 Goodbye.
    
    Could not fetch base from ftp.freebsd.org.
      Maybe your release (7.1-RELEASE) is specified incorrectly or the host ftp.freebsd.org     does not provide that release build.
      Use the -r option to specify an existing release or the -h option to specify an     alternative ftp server.
    Querying your ftp-server... The ftp server you specified (ftp.freebsd.org) seems to         provide the following builds:
    Trying 193.162.146.4...
    total 10
    drwxrwxr-x  13 1006  1006   512 Feb 20  2011 8.2-RELEASE
    drwxrwxr-x  13 1006  1006   512 Apr 10  2012 8.3-RELEASE
    lrwxr-xr-x   1 1006  1006    16 Jan  7  2012 9.0-RELEASE -> i386/9.0-RELEASE
    drwxrwxr-x   7 1006  1006  1024 Feb 19  2012 ISO-IMAGES
    -rw-rw-r--   1 1006  1006   637 Nov 23  2005 README.TXT
    drwxrwxr-x   5 1006  1006   512 Nov  2 02:59 i386
    

    I do not want to upgrade my freebsd installation. I have googled around; but all in vail.

    Thank you

    • voretaq7
      voretaq7 over 11 years
      Re: your ezjail problems - double-check your ezjail.conf file and make sure the source tree path is specified correctly. It sounds like your configuration file is missing or malformed. /// <Obligatory Lecture> You know 7.1 is a dead release, right? (and 7.4 - the last supported 7.x - dies in February per freebsd.org/security). The upgrade to 8.x (or even 8.x->9.x) isn't that painful. </Obligatory Lecture>
  • Player 2nd
    Player 2nd over 11 years
    Thanks, I did that too. About using ezjail, if you read my question, you know that did go well.
  • Steve Wills
    Steve Wills over 11 years
    Right, sorry, missed that. Personally, I've had good luck with ezjail, but I let it do everything except the network setup and the creation of the initial zfs filesystem for the jail. That seems to help things go well.