Parcourir la source

dhcp; begin tftp

tags/v1.0.0
Robin Thoni il y a 7 ans
révision
634ed02632
17 fichiers modifiés avec 300 ajouts et 0 suppressions
  1. 2
    0
      .gitignore
  2. 45
    0
      docker-compose.yml
  3. 2
    0
      env
  4. 27
    0
      isc-dhcp/Dockerfile
  5. 41
    0
      isc-dhcp/common.sh
  6. 38
    0
      isc-dhcp/dhcpd.conf
  7. 9
    0
      isc-dhcp/run.sh
  8. 1
    0
      isc-dhcp/vars-files
  9. 2
    0
      isc-dhcp/vars-vars
  10. 28
    0
      tftpd/Dockerfile
  11. 41
    0
      tftpd/common.sh
  12. 38
    0
      tftpd/dhcpd.conf
  13. 7
    0
      tftpd/run.sh
  14. 1
    0
      tftpd/vars-files
  15. 2
    0
      tftpd/vars-vars
  16. 9
    0
      tftpd/xinetd.tftp.conf
  17. 7
    0
      update_vars.sh

+ 2
- 0
.gitignore Voir le fichier

@@ -0,0 +1,2 @@
1
+/data
2
+*.swp

+ 45
- 0
docker-compose.yml Voir le fichier

@@ -0,0 +1,45 @@
1
+version: '2'
2
+
3
+services:
4
+    isc-dhcp:
5
+        build: ./isc-dhcp
6
+        container_name: dhcp-isc-dhcp
7
+        volumes:
8
+            - ./data/isc-dhcp:/data
9
+        network_mode: host
10
+#        networks:
11
+#            dhcp.internal.docker:
12
+#                aliases:
13
+#                    - isc-dhcp.dhcp.internal.docker
14
+#        ports:
15
+#            - "0.0.0.0:67:67/udp"
16
+        env_file:
17
+            - env
18
+
19
+    tftpd:
20
+        build: ./tftpd
21
+        container_name: dhcp-tftpd
22
+        volumes:
23
+            - ./data/tftpd/tftp:/srv/tftp/
24
+        networks:
25
+            dhcp.internal.docker:
26
+                aliases:
27
+                    - tftpd.dhcp.internal.docker
28
+        ports:
29
+            - "0.0.0.0:69:69/udp"
30
+        env_file:
31
+            - env
32
+
33
+#    dhcp-recursor:
34
+#        build: ./dhcp-recursor
35
+#        container_name: dhcp-dhcp-recursor
36
+#        networks:
37
+#            dhcp.internal.docker:
38
+#                aliases:
39
+#                    - dhcp-recursor.dhcp.internal.docker
40
+#        env_file:
41
+#            - env
42
+
43
+
44
+networks:
45
+    dhcp.internal.docker:

+ 2
- 0
env Voir le fichier

@@ -0,0 +1,2 @@
1
+DNS_HOST_ROUTER=router
2
+IP_HOST8ROUTER=

+ 27
- 0
isc-dhcp/Dockerfile Voir le fichier

@@ -0,0 +1,27 @@
1
+FROM debian:jessie
2
+
3
+MAINTAINER Robin Thoni <robin@rthoni.com>
4
+
5
+ARG CONFIG_DIR=/etc/default/config-files/
6
+
7
+RUN apt-get update && apt-get -y install\
8
+        isc-dhcp-server &&\
9
+        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
10
+
11
+RUN rm -rf /var/log/*
12
+
13
+COPY ./vars-vars /etc/vars-vars
14
+
15
+COPY ./vars-files /etc/vars-files
16
+
17
+COPY ./common.sh /common.sh
18
+
19
+COPY ./run.sh /run.sh
20
+
21
+RUN mkdir "${CONFIG_DIR}"
22
+
23
+COPY dhcpd.conf "${CONFIG_DIR}"/dhcpd.conf
24
+
25
+EXPOSE 80
26
+
27
+CMD ["/run.sh"]

+ 41
- 0
isc-dhcp/common.sh Voir le fichier

@@ -0,0 +1,41 @@
1
+export CONFIG_DIR="/etc/default/config-files/"
2
+
3
+resolv_host()
4
+{
5
+  hostname="${1}"
6
+  ip=$(getent hosts "${hostname}" | cut -d' ' -f1)
7
+  echo "${ip}"
8
+}
9
+
10
+replace_var()
11
+{
12
+  file="${1}"
13
+  var="${2}"
14
+  sed -e "s?${var}?${!var}?g" -i "${file}"
15
+}
16
+
17
+replace_vars()
18
+{
19
+  file="${1}"
20
+  for var in $(cat /etc/vars-vars)
21
+  do
22
+    replace_var "${file}" "${var}"
23
+  done
24
+}
25
+
26
+replace_files()
27
+{
28
+  cat /etc/vars-files | while read line
29
+  do
30
+    filesrc="${CONFIG_DIR}$(echo "${line}" | awk '{print $1}')"
31
+    filedst=$(echo "${line}" | awk '{print $2}')
32
+    if [ -f "${filesrc}" ]
33
+    then
34
+      echo "Expanding file ${filesrc} to ${filedst}"
35
+      cp "${filesrc}" "${filedst}"
36
+      replace_vars "${filedst}"
37
+    else
38
+      echo "File ${filesrc} does not exist. Skipping."
39
+    fi
40
+  done
41
+}

+ 38
- 0
isc-dhcp/dhcpd.conf Voir le fichier

@@ -0,0 +1,38 @@
1
+ddns-update-style none;
2
+
3
+option classless-routes code 121 = array of unsigned integer 8;
4
+option classless-routes-win code 249 = array of unsigned integer 8;
5
+
6
+default-lease-time 600;
7
+max-lease-time 7200;
8
+
9
+use-host-decl-names on;
10
+
11
+authoritative;
12
+
13
+log-facility local7;
14
+
15
+subnet 10.15.100.0 netmask 255.255.255.0 {
16
+
17
+  range 10.15.100.50 10.15.100.250;
18
+  option subnet-mask 255.255.255.0;
19
+  option broadcast-address 10.15.100.255;
20
+  option routers 10.15.100.2;
21
+
22
+  option domain-name "site.rthoni.com rthoni.com";
23
+  option domain-name-servers 10.15.100.1;
24
+
25
+  #option classless-routes 24, 10,15,42, 10.15.12,2;
26
+  #option classless-routes-win 24, 10,15,42, 10.15.12,2;
27
+
28
+  next-server 10.15.100.2;
29
+  if exists user-class and ( option user-class = "iPXE-rthoni" ) {
30
+    filename "http://netboot/boot.ipxe";
31
+  }
32
+  else {
33
+    filename "ipxe-rthoni.kpxe";
34
+  }
35
+  option root-path "10.15.100.1:/pxeroot/ubuntu";
36
+
37
+}
38
+

+ 9
- 0
isc-dhcp/run.sh Voir le fichier

@@ -0,0 +1,9 @@
1
+#! /usr/bin/env bash
2
+
3
+. /common.sh
4
+
5
+replace_files
6
+
7
+touch /data/dhcpd.leases
8
+
9
+exec dhcpd -4 -f --no-pid -d -cf /etc/dhcp/dhcpd.conf -lf /data/dhcpd.leases

+ 1
- 0
isc-dhcp/vars-files Voir le fichier

@@ -0,0 +1 @@
1
+dhcpd.conf /etc/dhcp/dhcpd.conf

+ 2
- 0
isc-dhcp/vars-vars Voir le fichier

@@ -0,0 +1,2 @@
1
+DNS_HOST_ROUTER
2
+IP_HOST8ROUTER

+ 28
- 0
tftpd/Dockerfile Voir le fichier

@@ -0,0 +1,28 @@
1
+FROM debian:jessie
2
+
3
+MAINTAINER Robin Thoni <robin@rthoni.com>
4
+
5
+ARG CONFIG_DIR=/etc/default/config-files/
6
+
7
+RUN apt-get update && apt-get -y install\
8
+        tftpd-hpa\
9
+        xinetd &&\
10
+        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
11
+
12
+RUN rm -rf /var/log/*
13
+
14
+COPY ./vars-vars /etc/vars-vars
15
+
16
+COPY ./vars-files /etc/vars-files
17
+
18
+COPY ./common.sh /common.sh
19
+
20
+COPY ./run.sh /run.sh
21
+
22
+RUN mkdir "${CONFIG_DIR}"
23
+
24
+COPY xinetd.tftp.conf "${CONFIG_DIR}"/tftp
25
+
26
+EXPOSE 80
27
+
28
+CMD ["/run.sh"]

+ 41
- 0
tftpd/common.sh Voir le fichier

@@ -0,0 +1,41 @@
1
+export CONFIG_DIR="/etc/default/config-files/"
2
+
3
+resolv_host()
4
+{
5
+  hostname="${1}"
6
+  ip=$(getent hosts "${hostname}" | cut -d' ' -f1)
7
+  echo "${ip}"
8
+}
9
+
10
+replace_var()
11
+{
12
+  file="${1}"
13
+  var="${2}"
14
+  sed -e "s?${var}?${!var}?g" -i "${file}"
15
+}
16
+
17
+replace_vars()
18
+{
19
+  file="${1}"
20
+  for var in $(cat /etc/vars-vars)
21
+  do
22
+    replace_var "${file}" "${var}"
23
+  done
24
+}
25
+
26
+replace_files()
27
+{
28
+  cat /etc/vars-files | while read line
29
+  do
30
+    filesrc="${CONFIG_DIR}$(echo "${line}" | awk '{print $1}')"
31
+    filedst=$(echo "${line}" | awk '{print $2}')
32
+    if [ -f "${filesrc}" ]
33
+    then
34
+      echo "Expanding file ${filesrc} to ${filedst}"
35
+      cp "${filesrc}" "${filedst}"
36
+      replace_vars "${filedst}"
37
+    else
38
+      echo "File ${filesrc} does not exist. Skipping."
39
+    fi
40
+  done
41
+}

+ 38
- 0
tftpd/dhcpd.conf Voir le fichier

@@ -0,0 +1,38 @@
1
+ddns-update-style none;
2
+
3
+option classless-routes code 121 = array of unsigned integer 8;
4
+option classless-routes-win code 249 = array of unsigned integer 8;
5
+
6
+default-lease-time 600;
7
+max-lease-time 7200;
8
+
9
+use-host-decl-names on;
10
+
11
+authoritative;
12
+
13
+log-facility local7;
14
+
15
+subnet 10.15.100.0 netmask 255.255.255.0 {
16
+
17
+  range 10.15.100.50 10.15.100.250;
18
+  option subnet-mask 255.255.255.0;
19
+  option broadcast-address 10.15.100.255;
20
+  option routers 10.15.100.2;
21
+
22
+  option domain-name "site.rthoni.com rthoni.com";
23
+  option domain-name-servers 10.15.100.1;
24
+
25
+  #option classless-routes 24, 10,15,42, 10.15.12,2;
26
+  #option classless-routes-win 24, 10,15,42, 10.15.12,2;
27
+
28
+  next-server 10.15.100.2;
29
+  if exists user-class and ( option user-class = "iPXE-rthoni" ) {
30
+    filename "http://netboot/boot.ipxe";
31
+  }
32
+  else {
33
+    filename "ipxe-rthoni.kpxe";
34
+  }
35
+  option root-path "10.15.100.1:/pxeroot/ubuntu";
36
+
37
+}
38
+

+ 7
- 0
tftpd/run.sh Voir le fichier

@@ -0,0 +1,7 @@
1
+#! /usr/bin/env bash
2
+
3
+. /common.sh
4
+
5
+replace_files
6
+
7
+exec xinetd -dontfork

+ 1
- 0
tftpd/vars-files Voir le fichier

@@ -0,0 +1 @@
1
+tftp /etc/xinetd.d/tftp

+ 2
- 0
tftpd/vars-vars Voir le fichier

@@ -0,0 +1,2 @@
1
+DNS_HOST_ROUTER
2
+IP_HOST8ROUTER

+ 9
- 0
tftpd/xinetd.tftp.conf Voir le fichier

@@ -0,0 +1,9 @@
1
+service tftp
2
+  {
3
+    disable             = no
4
+    socket_type = dgram
5
+    wait                = yes
6
+    user                = root
7
+    server              = /usr/sbin/in.tftpd
8
+    server_args = /srv/tftp/
9
+  }

+ 7
- 0
update_vars.sh Voir le fichier

@@ -0,0 +1,7 @@
1
+#! /usr/bin/env sh
2
+
3
+vars=$(cat env | cut -d= -f1)
4
+for docker in isc-dhcp tftpd
5
+do
6
+  echo "${vars}" > "./${docker}/vars-vars"
7
+done

Chargement…
Annuler
Enregistrer