Hello Katherine,

Le mardi 05 janvier 2021 à 15:49 -0600, Katherine Cox-Buday a écrit :
> Is it possible to define an operating-system which runs DHCP on one
> NIC,
> and has a static address on the other?

For a slightly different problem (adding a static ipv6 on the same
interface, [1]), I ended up creating a service that just did "ip
address add dev <device> <address>" on startup, and it seems to work.
Maybe you can do something similar? The "ip" program is from the
iproute package, defined in (gnu packages linux).

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44571

Hoping that it helps.

divoplade
(define-module (gnu services static-ipv6)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (guix gexp)
  #:use-module (guix modules)
  #:use-module (guix records)
  #:use-module (gnu packages linux)
  #:use-module (ice-9 match)
  #:use-module (ice-9 optargs))

(define-record-type* <static-ipv6-configuration>
  static-ipv6-configuration
  make-static-ipv6-configuration
  static-ipv6-configuration?
  (iproute static-ipv6-configuration-iproute (default iproute))
  (address static-ipv6-configuration-address)
  (interface static-ipv6-configuration-interface))

(export <static-ipv6-configuration>
	static-ipv6-configuration
	make-static-ipv6-configuration
	static-ipv6-configuration?
	static-ipv6-configuration-iproute
	static-ipv6-configuration-address
	static-ipv6-configuration-interface)

(define static-ipv6-shepherd-service
  (match-lambda
    (($ <static-ipv6-configuration>
	iproute address interface)
     (list
      (shepherd-service
       (provision '(static-ipv6))
       (documentation (format #f "Add ~a/128 to interface ~a"
			      address interface))
       (requirement '(user-processes loopback syslogd))
       (start
	#~(lambda _
	    (system*
	     (string-append #$iproute "/sbin/ip")
	     "address"
	     "add"
	     "dev"
	     #$interface
	     (string-append #$address "/128"))))
       (stop
	#~(lambda _
	    (system*
	     (string-append #$iproute "/sbin/ip")
	     "address"
	     "delete"
	     "dev"
	     #$interface
	     (string-append #$address "/128")))))))))

(define-public static-ipv6-service-type
  (service-type (name 'static-ipv6)
		(extensions
		 (list
		  (service-extension
		   shepherd-root-service-type
		   static-ipv6-shepherd-service)))))

Reply via email to