piątek, 17 stycznia 2014

Secure web directory with exclude

Last time I needed to secure on of my websites. I set password, used htaccess and ...I got error on my main page. The reason was simple - main page invoked to file in my secure directory. I needed to exclude this file from my secure directory. Below is solution.
# password protection allowing multiple resources AuthType Basic AuthName "Restricted Area" AuthUserFile /home/path/.htpasswd AuthGroupFile /dev/null Require valid-user # allow public access to the following resources SetEnvIf Request_URI "(path/to/directory_01/)$" allow SetEnvIf Request_URI "(path/to/directory_02/)$" allow SetEnvIf Request_URI "(path/to/file\.php)$" allow SetEnvIf Request_URI "(path/to/file\.html)$" allow SetEnvIf Request_URI "(path/to/another/resource/)$" allow SetEnvIf Request_URI "(path/to/yet/another/resource/)$" allow Order allow,deny Allow from env=allow Satisfy any
Of course you can also use "Allow from " to limiting access to secure directory.

środa, 20 listopada 2013

mdadm "lost" discs

A few days ago I had to stop my systems. One of them had different kind of storage like: luns, nfs and software raids. After turned on system I realized that I had had no software raid. I checked if everything was connected and checked if discs exists.
mdadm --examine /dev/sd[b-t] /dev/sdc: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : da8f3a5d:10f75bee:f074ba7e:f0494c09 Update Time : Tue Dec 11 13:59:58 2012 Checksum : d24bdccc - correct Events : 0 Chunk Size : 512K Device Role : Active device 7 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdd: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : c4d19ddc:f5dc1884:c6ef0844:3abe1c66 Update Time : Tue Dec 11 13:59:58 2012 Checksum : 98af3bd - correct Events : 0 Chunk Size : 512K Device Role : Active device 8 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sde: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 51e205a2:40aa348f:3f2041a9:872d3e1f Update Time : Tue Dec 11 13:59:58 2012 Checksum : f868715b - correct Events : 0 Chunk Size : 512K Device Role : Active device 9 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdf: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 1832c689:2cb35bfc:d2c97cf5:d84c985d Update Time : Tue Dec 11 13:59:58 2012 Checksum : d7e592ea - correct Events : 0 Chunk Size : 512K Device Role : Active device 0 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdg: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 5a9a6781:53904dfc:0f5789c9:e0df60e8 Update Time : Tue Dec 11 13:59:58 2012 Checksum : 2e4df89a - correct Events : 0 Chunk Size : 512K Device Role : Active device 1 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdh: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : afa5008b:efc248ab:5ab3bce0:2def6ad1 Update Time : Tue Dec 11 13:59:58 2012 Checksum : e71fa223 - correct Events : 0 Chunk Size : 512K Device Role : Active device 2 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdi: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : c8e16d74:a1940d4c:5a802c6a:5173a94c Update Time : Tue Dec 11 13:59:58 2012 Checksum : 76000112 - correct Events : 0 Chunk Size : 512K Device Role : Active device 3 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdj: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 53051171:604d9634:a7f5c2b6:14c2bddd Update Time : Tue Dec 11 13:59:58 2012 Checksum : 38d6a16e - correct Events : 0 Chunk Size : 512K Device Role : Active device 4 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdk: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : fc3706df:d1f2df92:f50a37a7:55fd1845 Update Time : Tue Dec 11 13:59:58 2012 Checksum : 5ce4ca18 - correct Events : 0 Chunk Size : 512K Device Role : Active device 5 Array State : AAAAAAAAAA ('A' == active, '.' == missing) /dev/sdl: Magic : a92b4efc Version : 1.2 Feature Map : 0x0 Array UUID : 2632f0c3:b113d4e9:056228c1:d30a6ab0 Name : synat2:0 (local to host synat2) Creation Time : Tue Dec 11 13:59:58 2012 Raid Level : raid0 Raid Devices : 10 Avail Dev Size : 47997696 (22.89 GiB 24.57 GB) Data Offset : 2048 sectors Super Offset : 8 sectors State : clean Device UUID : 6ae2fd1e:30297e6c:4a26a015:2edcfe2c Update Time : Tue Dec 11 13:59:58 2012 Checksum : ccc9a512 - correct Events : 0 Chunk Size : 512K Device Role : Active device 6 Array State : AAAAAAAAAA ('A' == active, '.' == missing)
Than I realized that in my mdadm.conf were entries with /dev/dm-*. It means that something was wrong because in /dev I had only 4 entries contained dm*. It turned out that my multipath configuration blocked other dm-* devices to be discovered. I switched dm to disk/by-id.
root@testing:~# cat /etc/mdadm/mdadm.conf | grep -v ^# CREATE owner=root group=disk mode=0660 auto=yes HOMEHOST MAILADDR root DEVICE /dev/disk/by-id/scsi-SATA_MARVELL_*
Did:
root@testing:~# mdadm --assemble --scan
and
root@testing:~# mount -a
Now everything works as it should.

wtorek, 29 października 2013

FreeBSD access via Xen console

To allow access via xen console you need to change /etc/ttys:

-ttyu0 /usr/libexec/getty std.9600 dialup off secure
+ttyu0 /usr/libexec/getty std.9600 dialup on secure

Than add few lines into /boot/loader.conf :

boot_multicons="YES"
boot_serial="YES"
comconsole_speed=9600
console="comconsole,vidconsole"

Now you can restart server.
Now you can access to FreeBSD console via xen:

[root@xenserver1 ~]# xl console "FreeBSD 9.2"

FreeBSD/amd64 (tanatos) (ttyu0)

login:
To end session on console please enter Ctrl+]

piątek, 25 października 2013

Xen add new virtual disc

Once I need to attach new disk on my VM machine. To do this I need make steps below :

1) Get storage UUID:

[root@xenserver1 ~]# xe sr-list 
uuid ( RO)                : 4e98e18e-1215-4fdb-baec-924bbef2a67e
          name-label ( RW): Remote ISO Library on: /mnt/iso_import
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : f30a1ead-37f2-0e3c-9583-073c176fc111
          name-label ( RW): Removable storage
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): udev
        content-type ( RO): disk


uuid ( RO)                : 419c98d3-1d98-3049-c579-439c31b33fd4
          name-label ( RW): XenServer Tools
    name-description ( RW): XenServer Tools ISOs
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : a9329bfa-e13e-2edd-8414-5920f03f27e5
          name-label ( RW): ISOS
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : cb128245-3dcb-9de6-319d-681cede9553f
          name-label ( RW): DVD drives
    name-description ( RW): Physical DVD drives
                host ( RO): xenserver1
                type ( RO): udev
        content-type ( RO): iso


uuid ( RO)                : f6375e1e-0ab7-b11c-e9dd-677da4436e15
          name-label ( RW): Local storage
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): lvm
        content-type ( RO): user
2) Create virtual disc:
[root@xenserver1 ~]# xe vdi-create name-label="zfs1" sr-uuid=f6375e1e-0ab7-b11c-e9dd-677da4436e15 type=user sm-config:type=raw virtual-size=10GiB
34a899b3-b3dd-4531-aee9-1fafb57517ca
[root@xenserver1 ~]# xe vdi-create name-label="zfs2" sr-uuid=f6375e1e-0ab7-b11c-e9dd-677da4436e15 type=user sm-config:type=raw virtual-size=10GiB
20c384f6-0504-4c7f-a3cf-08d28c6c0dc6
[root@xenserver1 ~]# xe vdi-list name-label=zfs1
uuid ( RO)                : 34a899b3-b3dd-4531-aee9-1fafb57517ca
          name-label ( RW): zfs1
    name-description ( RW): 
             sr-uuid ( RO): f6375e1e-0ab7-b11c-e9dd-677da4436e15
        virtual-size ( RO): 10737418240
            sharable ( RO): false
           read-only ( RO): false


[root@xenserver1 ~]# xe vdi-list name-label=zfs2
uuid ( RO)                : 20c384f6-0504-4c7f-a3cf-08d28c6c0dc6
          name-label ( RW): zfs2
    name-description ( RW): 
             sr-uuid ( RO): f6375e1e-0ab7-b11c-e9dd-677da4436e15
        virtual-size ( RO): 10737418240
            sharable ( RO): false
           read-only ( RO): false
3) Check virtual machine UUID for whom virtual disc should be attched:
[root@xenserver1 ~]# xe vm-list 
uuid ( RO)           : 68ce65a4-01ec-4a23-9016-011aa20e59cf
     name-label ( RW): Control domain on host: xenserver1
    power-state ( RO): running


uuid ( RO)           : 66a6fcc2-b5b9-1eb9-cd26-c26d8df1e204
     name-label ( RW): Hadoop-master
    power-state ( RO): running


uuid ( RO)           : a79bc6f8-54d7-a562-ba14-4f50db2efc9b
     name-label ( RW): FreeBSD 9.2
    power-state ( RO): running


uuid ( RO)           : 8ac1c052-8448-6d9b-0a55-6e91e5be406c
     name-label ( RW): FreeBSD10
    power-state ( RO): halted


uuid ( RO)           : 03070e1e-2b04-5e4b-87f9-5db7d69131bb
     name-label ( RW): Hadoop-slave2
    power-state ( RO): running


uuid ( RO)           : d122b3bf-e914-83b0-5761-1430f205fa9c
     name-label ( RW): Hadoop-slave1
    power-state ( RO): running
In my case it was FreeBSD 9.2 (uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b)

4) Get allowed numbers for VBD devices:

[root@xenserver1 ~]# xe vm-param-get uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b param-name=allowed-VBD-devices 
1; 2
5) Create virtual disc attached to VM:
[root@xenserver1 ~]# xe vbd-create device=1 vm-uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b vdi-uuid=34a899b3-b3dd-4531-aee9-1fafb57517ca bootable=false mode=RW type=Disk
f43711c3-be1e-a869-8888-408d94a70656
[root@xenserver1 ~]# xe vbd-create device=2 vm-uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b vdi-uuid=20c384f6-0504-4c7f-a3cf-08d28c6c0dc6 bootable=false mode=RW type=Disk
5dcf7ad9-f4ec-b3e3-ea0c-8edd0d35d53d
6) Optionally if you have Xen tools on board you can plug virtual disc live.
[root@xenserver1 ~]# xe vbd-plug uuid=f43711c3-be1e-a869-8888-408d94a70656
If everything goes right you should have new discs attached and working on virtual machine. On system:
shamrock@tanatos:~ % dmesg | grep xbd
xbd0: 30720MB  at device/vbd/768 on xenbusb_front0
xbd0: attaching as ada0
xbd1: 10240MB  at device/vbd/5632 on xenbusb_front0
xbd1: attaching as ada2
xbd2: 10240MB  at device/vbd/832 on xenbusb_front0
xbd2: attaching as ada1
On Xen:
[root@xenserver1 ~]# xe vbd-list vm-name-label=FreeBSD\ 9.2
uuid ( RO)             : 5dcf7ad9-f4ec-b3e3-ea0c-8edd0d35d53d
          vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
    vm-name-label ( RO): FreeBSD 9.2
         vdi-uuid ( RO): 20c384f6-0504-4c7f-a3cf-08d28c6c0dc6
            empty ( RO): false
           device ( RO): hdc


uuid ( RO)             : f43711c3-be1e-a869-8888-408d94a70656
          vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
    vm-name-label ( RO): FreeBSD 9.2
         vdi-uuid ( RO): 34a899b3-b3dd-4531-aee9-1fafb57517ca
            empty ( RO): false
           device ( RO): hdb


uuid ( RO)             : 17d014d8-0d28-76e9-b6dc-f8944a0c0244
          vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
    vm-name-label ( RO): FreeBSD 9.2
         vdi-uuid ( RO): a74f372f-2fcd-4121-a241-bd1e960a069c
            empty ( RO): false
           device ( RO): hda

środa, 23 października 2013

Create local ISO repository

Create with lvcreate place for repository:
[root@xenserver1 ~]# lvcreate -L 30G -n ISO2 VG_XenStorage-f6375e1e-0ab7-b11c-e9dd-677da4436e15
Make proper file system:
[root@xenserver1 ~]# mkfs.ext3 /dev/VG_XenStorage-f6375e1e-0ab7-b11c-e9dd-677da4436e15/ISO2 
Add lines to /ec/rc.local
[root@xenserver1 ~]# vi /etc/rc.local 

ISO=/dev/VG_XenStorage-f6375e1e-0ab7-b11c-e9dd-677da4436e15/ISO2
lvchange -ay $ISO
mount $ISO /mnt/iso_import

It's very important not to change /etc/fstab !!!

Last thing is to mount everything without restart:
[root@xenserver1 ~]# ISO=/dev/VG_XenStorage-f6375e1e-0ab7-b11c-e9dd-677da4436e15/ISO2
[root@xenserver1 ~]# lvchange -ay $ISO
[root@xenserver1 ~]# mount $ISO /mnt/iso_import
[root@xenserver1 ~]# xe-mount-iso-sr /mnt/iso_import -o bind
Result:
[root@xenserver1 ~]# xe sr-list
uuid ( RO)                : 4e98e18e-1215-4fdb-baec-924bbef2a67e
          name-label ( RW): Remote ISO Library on: /mnt/iso_import
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : f30a1ead-37f2-0e3c-9583-073c176fc111
          name-label ( RW): Removable storage
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): udev
        content-type ( RO): disk


uuid ( RO)                : 419c98d3-1d98-3049-c579-439c31b33fd4
          name-label ( RW): XenServer Tools
    name-description ( RW): XenServer Tools ISOs
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : cb128245-3dcb-9de6-319d-681cede9553f
          name-label ( RW): DVD drives
    name-description ( RW): Physical DVD drives
                host ( RO): xenserver1
                type ( RO): udev
        content-type ( RO): iso


uuid ( RO)                : f6375e1e-0ab7-b11c-e9dd-677da4436e15
          name-label ( RW): Local storage
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): lvm
        content-type ( RO): user

How to add network interface to VM on Citrix Xen via console

Check interfaces:
[root@xenserver1 ~]# xe pif-list 
uuid ( RO)                  : cc9937fa-0435-7664-a73a-c9bfa803e50e
                device ( RO): eth3
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): e7a75876-ee65-950e-7975-6751eca3795b


uuid ( RO)                  : 3a5ef383-650a-ded9-d636-4c86a6831443
                device ( RO): eth1
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): bd91ea1e-6184-4f7b-6360-0134f39b9751


uuid ( RO)                  : 4c04ef06-9707-67ac-1859-6e6617d507a7
                device ( RO): eth2
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): 8d829397-e8d1-fdc2-b62d-8b23cf6da7dd


uuid ( RO)                  : 41b55f45-91ff-90e1-0a13-dbb680e744e9
                device ( RO): eth0
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): 78613a9f-aede-edc6-39f4-40c4c5883de2


uuid ( RO)                  : 72ff5545-3d4b-5038-aa15-dc93998b8dab
                device ( RO): eth0
    currently-attached ( RO): true
                  VLAN ( RO): 21
          network-uuid ( RO): 8310ea88-dad4-c989-19db-5c5fdb8d3edc
Create internal interface - not bounded to any physical interface :
[root@xenserver1 ~]# xe network-create name-label="anylan" name-description="anylan for testing"
919b5b1c-201f-fed2-c39d-21946f278bdc
Create tagged network interface bounded to physical NIC:
[root@xenserver1 ~]# xe network-create name-label="vlan402" name-description="VLAN 402" 
d5b6969c-eff4-79b2-0088-7740f8a9b492


[root@xenserver1 ~]# xe vlan-create network-uuid=d5b6969c-eff4-79b2-0088-7740f8a9b492 pif-uuid=41b55f45-91ff-90e1-0a13-dbb680e744e9  vlan=402
7dadd3ec-b8a2-5b40-0855-0ef365dc9f00
Example pif-list after adding new interface
[root@xenserver1 ~]# xe pif-list 
uuid ( RO)                  : 7dadd3ec-b8a2-5b40-0855-0ef365dc9f00
                device ( RO): eth0
    currently-attached ( RO): true
                  VLAN ( RO): 402
          network-uuid ( RO): d5b6969c-eff4-79b2-0088-7740f8a9b492


uuid ( RO)                  : cc9937fa-0435-7664-a73a-c9bfa803e50e
                device ( RO): eth3
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): e7a75876-ee65-950e-7975-6751eca3795b


uuid ( RO)                  : 3a5ef383-650a-ded9-d636-4c86a6831443
                device ( RO): eth1
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): bd91ea1e-6184-4f7b-6360-0134f39b9751


uuid ( RO)                  : 4c04ef06-9707-67ac-1859-6e6617d507a7
                device ( RO): eth2
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): 8d829397-e8d1-fdc2-b62d-8b23cf6da7dd


uuid ( RO)                  : 41b55f45-91ff-90e1-0a13-dbb680e744e9
                device ( RO): eth0
    currently-attached ( RO): true
                  VLAN ( RO): -1
          network-uuid ( RO): 78613a9f-aede-edc6-39f4-40c4c5883de2


uuid ( RO)                  : 72ff5545-3d4b-5038-aa15-dc93998b8dab
                device ( RO): eth0
    currently-attached ( RO): true
                  VLAN ( RO): 21
          network-uuid ( RO): 8310ea88-dad4-c989-19db-5c5fdb8d3edc
Check VM to attach new interface: we need to know number of devices and vm-uuid.
[root@xenserver1 ~]# xe vm-list 
uuid ( RO)           : 68ce65a4-01ec-4a23-9016-011aa20e59cf
     name-label ( RW): Control domain on host: xenserver1
    power-state ( RO): running


uuid ( RO)           : 66a6fcc2-b5b9-1eb9-cd26-c26d8df1e204
     name-label ( RW): Hadoop-master
    power-state ( RO): running


uuid ( RO)           : a79bc6f8-54d7-a562-ba14-4f50db2efc9b
     name-label ( RW): FreeBSD 9.2
    power-state ( RO): running


uuid ( RO)           : 8ac1c052-8448-6d9b-0a55-6e91e5be406c
     name-label ( RW): FreeBSD10
    power-state ( RO): halted


uuid ( RO)           : 03070e1e-2b04-5e4b-87f9-5db7d69131bb
     name-label ( RW): Hadoop-slave2
    power-state ( RO): running


uuid ( RO)           : d122b3bf-e914-83b0-5761-1430f205fa9c
     name-label ( RW): Hadoop-slave1
    power-state ( RO): running

[root@xenserver1 ~]# xe vif-list vm-name-label=FreeBSD\ 9.2
uuid ( RO)            : 49a107e2-0e81-a9dd-0595-218c07fe1af8
         vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
          device ( RO): 2
    network-uuid ( RO): 56d7fd62-ba47-c12c-e371-bc7908739ad1


uuid ( RO)            : 03932dbf-d7e4-ed7d-d649-ac431a97d962
         vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
          device ( RO): 1
    network-uuid ( RO): 8310ea88-dad4-c989-19db-5c5fdb8d3edc
Attach interface to VM:
[root@xenserver1 ~]# xe vif-create network-uuid=d5b6969c-eff4-79b2-0088-7740f8a9b492 vm-uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b device=3 mac=random
758cf24a-2904-f3aa-8ed4-17d6ffebf032

[root@xenserver1 ~]# xe vif-create network-uuid=919b5b1c-201f-fed2-c39d-21946f278bdc  vm-uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b  device=4 mac=random
3504d19f-2413-e066-6d30-1878adfbd117
Result:

[root@xenserver1 ~]# xe vif-list vm-name-label=FreeBSD\ 9.2
uuid ( RO)            : 49a107e2-0e81-a9dd-0595-218c07fe1af8
         vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
          device ( RO): 2
    network-uuid ( RO): 56d7fd62-ba47-c12c-e371-bc7908739ad1


uuid ( RO)            : 758cf24a-2904-f3aa-8ed4-17d6ffebf032
         vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
          device ( RO): 3
    network-uuid ( RO): d5b6969c-eff4-79b2-0088-7740f8a9b492


uuid ( RO)            : 03932dbf-d7e4-ed7d-d649-ac431a97d962
         vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
          device ( RO): 1
    network-uuid ( RO): 8310ea88-dad4-c989-19db-5c5fdb8d3edc


uuid ( RO)            : 3504d19f-2413-e066-6d30-1878adfbd117
         vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
          device ( RO): 4
    network-uuid ( RO): 919b5b1c-201f-fed2-c39d-21946f278bdc
Depends of configuration probably you'll need to shutdown your machine and start it again thus system could determine network interface.