当前位置:   article > 正文

打印机 ansible配置dhcp和打印机_打印机网络dhcp

打印机网络dhcp

部署dhcp服务器

主机发送Discover报文
目标为广播地址
同一网段的dhcp收到报文后,dhcp响应一个offer报文
offer报文:dhcp自己的ip地址。和客户端ip以及使用周期,和客户端ip网络参数
最后主机单独发一个request报文 给那个选择的dhcp服务器 (解决多个dhcp在同一网段都提供offer的问题,主要是先到先得)
dhcp最后发送一个ack确认报文给主机

dhcp和主机不在同一网段得配置dhcp中继
客户端无法指定我可以单独使用哪个dhcp

实践

  1. 1>安装包
  2. [root@servera ~]# yum install -y dhcp-server
  3. 2> 准本配置文件
  4. [root@servera ~]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
  5. cp: overwrite '/etc/dhcp/dhcpd.conf'? y 这个模板十分好用
  6. [root@servera ~]#
  7. default-lease-time 600;
  8. max-lease-time 7200;
  9. log-facility local7;配置了日志设备,那么你就需要在rsyslog中,定义发送到这个local7的日志要转存在哪个日志文件内
  10. vim /etc/dhcp/dhcpd.conf
  11. authoritative;
  12. log-facility local7;
  13. subnet 192.168.0.0 netmask 255.255.255.0 { 定义子网
  14. range 192.168.0.200 192.168.0.254; 分配IP地址的范围
  15. default-lease-time 600; 定义默认租期
  16. max-lease-time 7200;
  17. #option routers 192.168.0.1; 定义网关的
  18. option domain-search "example.com"; 定义域名
  19. option domain-name-servers 172.25.254.254; DNS服务器
  20. option broadcast-address 192.168.0.255; 广播地址 #可以忽略
  21. # option next-server 指定tftp服务器的IP PXE
  22. # filename ""引导文件在哪里 PXE
  23. }
  24. dhcpd -t #这个命令可以验证配置文件
  25. 3> 启动DHCP服务器
  26. [root@servera ~]# systemctl enable --now dhcpd
  27. [root@servera ~]# firewall-cmd --permanent --add-service=dhcp
  28. success
  29. [root@servera ~]# firewall-cmd --reload
  30. success
  31. 4> 客户端怎么操作
  32. [root@serverb ~]# nmcli connection add type ethernet con-name eth1 ifname eth1 ipv4.method auto 就只需要把地址的方式改成auto
  33. Connection 'eth1' (d008c5e7-6868-448a-8a16-133502072777) successfully added.
  34. [root@serverb ~]# nmcli connection up eth1
  35. 5> 固定IP地址。给一个MAC地址,分配一个特定的地址
  36. host serverc {
  37. hardware ethernet 52:54:00:01:fa:0c; MAC
  38. fixed-address 192.168.0.150; 固定的IP地址
  39. }
  40. [root@serverc ~]# nmcli connection add type ethernet con-name eth1 ifname eth1 ipv4.method auto
  41. Connection 'eth1' (4dc7753b-fe97-4bc8-97f3-316b373c29c1) successfully added.
  42. [root@serverc ~]# nmcli connection up eth1
  43. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/40)
  44. [root@serverc ~]#
  45. [root@servera dhcp-server]# systemctl status dhcpd
  46. ● dhcpd.service - DHCPv4 Server Daemon
  47. Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
  48. Active: active (running) since Mon 2022-09-05 18:40:00 CST; 3min 54s ago
  49. Docs: man:dhcpd(8)
  50. man:dhcpd.conf(5)
  51. Main PID: 24264 (dhcpd)
  52. Status: "Dispatching packets..."
  53. Tasks: 1 (limit: 11250)
  54. Memory: 4.9M
  55. CGroup: /system.slice/dhcpd.service
  56. └─24264 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
  57. Sep 05 18:40:06 servera.lab.example.com dhcpd[24264]: DHCPOFFER on 192.168.0.201 to 52:54:00:02:fa:0c (serverc) via eth1
  58. Sep 05 18:40:06 servera.lab.example.com dhcpd[24264]: DHCPREQUEST for 192.168.0.201 (192.168.0.10) from 52:54:00:02:fa:0c (serverc) via eth1
  59. Sep 05 18:40:06 servera.lab.example.com dhcpd[24264]: DHCPACK on 192.168.0.201 to 52:54:00:02:fa:0c (serverc) via eth1
  60. Sep 05 18:40:06 servera.lab.example.com dhcpd[24264]: DHCPOFFER on 192.168.0.202 to 52:54:00:02:fa:0d (serverd) via eth1
  61. Sep 05 18:40:06 servera.lab.example.com dhcpd[24264]: DHCPREQUEST for 192.168.0.202 (192.168.0.10) from 52:54:00:02:fa:0d (serverd) via eth1
  62. Sep 05 18:40:06 servera.lab.example.com dhcpd[24264]: DHCPACK on 192.168.0.202 to 52:54:00:02:fa:0d (serverd) via eth1
  63. Sep 05 18:42:37 servera.lab.example.com dhcpd[24264]: DHCPDISCOVER from 52:54:00:01:fa:0b via eth1
  64. Sep 05 18:42:38 servera.lab.example.com dhcpd[24264]: DHCPOFFER on 192.168.0.203 to 52:54:00:01:fa:0b (serverb) via eth1
  65. Sep 05 18:42:38 servera.lab.example.com dhcpd[24264]: DHCPREQUEST for 192.168.0.203 (192.168.0.10) from 52:54:00:01:fa:0b (serverb) via eth1
  66. Sep 05 18:42:38 servera.lab.example.com dhcpd[24264]: DHCPACK on 192.168.0.203 to 52:54:00:01:fa:0b (serverb) via eth1
  67. 从dhcpd[24264]可以看到 dhcp的工作过程,与理论一致

dhcp6

ipv6得结合网络设备来分配网关
ipv6得与网络设备结合得到完整的功能,所以会很麻烦

无线状态地址自动配置slaac 方法依赖于路由器为客户端提系统提供网络配置

radvump查看公告信息
也可以通过linux模拟路由器 以提供slaac功能
slaac可也提供网关 ipv6前缀 dns服务器 dns搜索列表功能

实践

  1. [root@workstation ~]# lab dhcp-automation start
  2. [root@serverd ~]# systemctl status radvd.service
  3. ● radvd.service - Router advertisement daemon for IPv6
  4. Loaded: loaded (/usr/lib/systemd/system/radvd.service; enabled; vendor preset: disabled)
  5. Active: active (running) since Mon 2022-09-05 19:27:45 CST; 56s ago
  6. Process: 8169 ExecStart=/usr/sbin/radvd $OPTIONS (code=exited, status=0/SUCCESS)
  7. Main PID: 8171 (radvd)
  8. Tasks: 2 (limit: 11250)
  9. Memory: 864.0K
  10. CGroup: /system.slice/radvd.service
  11. ├─8171 /usr/sbin/radvd -u radvd
  12. └─8172 /usr/sbin/radvd -u radvd
  13. Sep 05 19:27:45 serverd.lab.example.com systemd[1]: Starting Router advertisement daemon for IPv6...
  14. Sep 05 19:27:45 serverd.lab.example.com radvd[8169]: version 2.17 started
  15. Sep 05 19:27:45 serverd.lab.example.com systemd[1]: Started Router advertisement daemon for IPv6.
  16. [root@serverd ~]#
  17. 配置ipv6
  18. 1>serverd 模拟路由器配置SLAAC功能。需要这个东西提供网关
  19. [root@serverd ~]# cat /etc/radvd.conf
  20. interface eth1
  21. {
  22. AdvSendAdvert on;
  23. AdvManagedFlag on;
  24. AdvOtherConfigFlag on;
  25. MaxRtrAdvInterval 60;
  26. };
  27. 2> radvd 软件包提供了一个工具radvdump 用来获取路由公告信息(路由器来提供的,)
  28. # based on Router Advertisement from fe80::5a83:c374:2215:148f IPV6的网关
  29. # received by interface eth1
  30. #
  31. interface eth1
  32. {
  33. AdvSendAdvert on;
  34. # Note: {Min,Max}RtrAdvInterval cannot be obtained with radvdump
  35. AdvManagedFlag on; 通过DHCP6来获取IP地址
  36. AdvOtherConfigFlag on; IPv6 路由器指⽰客⼾端查询 DHCPv6 服务器,
  37. AdvReachableTime 0;
  38. AdvRetransTimer 0;
  39. AdvCurHopLimit 64;
  40. AdvDefaultLifetime 180;
  41. AdvHomeAgentFlag off;
  42. AdvDefaultPreference medium;
  43. AdvSourceLLAddress on;
  44. }; # End of interface definition
  45. 2>DHCPV6功能: 比如网络信息,IP,DNS等都是有他来提供的
  46. 3> 部署安装包
  47. [root@servera ~]# yum install -y dhcp-server
  48. 4> 修改配置文件
  49. [root@servera ~]# cp /usr/share/doc/dhcp-server/dhcpd6.conf.example /etc/dhcp/dhcpd6.conf
  50. cp: overwrite '/etc/dhcp/dhcpd6.conf'? y
  51. [root@servera ~]#cat /etc/dhcp/dhcpd6.conf 唯一的不同时不能设置网关
  52. authoritative;
  53. subnet6 fde2:6494:1e09:2::/64 {
  54. range6 fde2:6494:1e09:2::20 fde2:6494:1e09:2::60;
  55. option dhcp6.name-servers fde2:6494:1e09:2::d;
  56. option dhcp6.domain-search "backend.lab.example.com";
  57. default-lease-time 600; max-lease-time 7200;
  58. }
  59. [root@servera ~]# nmcli connection add type ethernet con-name eth1 ifname eth1 ipv6.addresses fde2:6494:1e09:2::a/64 ipv6.method manual
  60. Connection 'eth1' (eb7dc998-d861-435c-8abd-2b7f061f8957) successfully added.
  61. [root@servera ~]# nmcli connection up eth1
  62. [root@servera ~]# systemctl enable --now dhcpd6.service
  63. Created symlink /etc/systemd/system/multi-user.target.wants/dhcpd6.service → /usr/lib/systemd/system/dhcpd6.service.
  64. [root@servera ~]# firewall-cmd --add-service=dhcpv6 --permanent
  65. success
  66. [root@servera ~]# firewall-cmd --reload
  67. success
  68. [root@servera ~]#
  69. [root@serverc ~]# nmcli connection add type ethernet ifname eth1 con-name eth1 ipv6.method auto
  70. Connection 'eth1' (95356996-edb3-4750-8170-e341cb604c57) successfully added.
  71. [root@serverc ~]# nmcli connection up eth1
  72. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
  73. [root@serverc ~]#
  74. 5> 默认网关
  75. [root@serverc ~]# ip -6 route
  76. ::1 dev lo proto kernel metric 256 pref medium
  77. fde2:6494:1e09:2::60 dev eth1 proto kernel metric 100 pref medium
  78. fe80::/64 dev eth1 proto kernel metric 100 pref medium
  79. fe80::/64 dev eth0 proto kernel metric 106 pref medium
  80. default via fe80::5a83:c374:2215:148f dev eth1 proto ra metric 100 pref medium
  81. 这个网关来自于发布公告的本地链路服务器,可也发现与默认网关一样
  82. 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
  83. link/ether 52:54:00:01:fa:0d brd ff:ff:ff:ff:ff:ff
  84. inet 192.168.0.220/24 brd 192.168.0.255 scope global dynamic noprefixroute eth1
  85. valid_lft 101sec preferred_lft 101sec
  86. inet6 fde2:6494:1e09:2::d/64 scope global noprefixroute
  87. valid_lft forever preferred_lft forever
  88. inet6 fe80::5a83:c374:2215:148f/64 scope link noprefixroute
  89. 不使用fe80
  90. 开启转发
  91. [root@serverd ~]# sysctl -a | grep forward | grep ipv6
  92. net.ipv6.conf.all.forwarding = 1
  93. 改变ipv6地址
  94. fe80::5a83:c374:2215:148f/64

ansible 自动化

  1. 流程
  2. 一:安装包
  3. 二:配置文件,notify: jinjia2 纯粹的文件
  4. 三: 如果有数据,传数据: web服务:
  5. 四: 服务和防火墙
  6. 五: handlers : 通过handlers来触发重新启动服务
  7. [student@workstation ~]$ lab dhcp-automation start
  8. 获取配置文件与清单文件
  9. - name: Deployment DHCP
  10. hosts: all
  11. become: true
  12. vars:
  13. network_connections:
  14. - name: eth1
  15. state: up
  16. type: ethernet
  17. mac: 52:54:00:01:fa:0a
  18. ip:
  19. address:
  20. - 192.168.0.10/24
  21. - fde2:6494:1e09:2::a/64
  22. tasks:
  23. - name: config ip address on dhcpservers
  24. include_role:
  25. name: rhel-system-roles.network
  26. when: inventory_hostname == "servera.lab.example.com"
  27. - name: install dhcpd package
  28. yum:
  29. name: dhcp-server
  30. state: present
  31. when: inventory_hostname == "servera.lab.example.com"
  32. - name: prepate dhcp config file
  33. copy:
  34. src: files/dhcpd.conf
  35. dest: /etc/dhcp/dhcpd.conf
  36. notify: restart dhcp4
  37. when: inventory_hostname == "servera.lab.example.com"
  38. - name: prepate dhcp6 config file
  39. copy:
  40. src: files/dhcpd6.conf
  41. dest: /etc/dhcp/dhcpd6.conf
  42. notify: restart dhcp6
  43. when: inventory_hostname == "servera.lab.example.com"
  44. - name: start dhcpd service
  45. service:
  46. name: "{{ item }}"
  47. state: started
  48. enabled: yes
  49. loop:
  50. - dhcpd
  51. - dhcpd6
  52. when: inventory_hostname == "servera.lab.example.com"
  53. - name: config firewarrd
  54. firewalld:
  55. service: "{{ item }}"
  56. state: enabled
  57. immediate: yes
  58. permanent: yes
  59. loop:
  60. - dhcp
  61. - dhcpv6
  62. when: inventory_hostname == "servera.lab.example.com"
  63. handlers:
  64. - name: restart dhcp
  65. service:
  66. name: dhcpd
  67. state: started
  68. when: inventory_hostname == "servera.lab.example.com"
  69. - name: restart dhcp6
  70. service:
  71. name: dhcpd6
  72. state: started
  73. when: inventory_hostname == "servera.lab.example.com"
  74. clients:
  75. [student@workstation dhcp-automation]$ cat client.yml
  76. ---
  77. - name: Deployment DHCP
  78. hosts: clients
  79. become: true
  80. vars:
  81. network_connections:
  82. - name: eth1
  83. state: up
  84. type: ethernet
  85. interface_name: eth1
  86. ip:
  87. dhcp4: yes
  88. auto6: yes
  89. tasks:
  90. - name: config ip address on dhcpservers
  91. include_role:
  92. name: rhel-system-roles.network

打印机

  1. 5.1.1 描述 CUPS 打印架构
  2. 打印机由 CUPS 在红帽企业 Linux 中进⾏管理,这是⼀种开源的模块化软件套件,最初由 Easy Software
  3. Products 开发,⽬前由 Apple 领导。
  4. CUPS 可以使⽤多个协议与打印机和打印服务器通信。在⼤多数情况下, Internet 打印协议 (IPP)是使⽤
  5. CUPS 与打印机通信的⾸选机制。此协议是对 HTTP/1.1 的修改,它受到⼤多数现代⽹络和 USB 打印机
  6. 的本地⽀持,通常使⽤ TCP 端⼝ 631。CUPS 可以⽀持直接连接的打印机(例如,使⽤ 并⾏、串⾏或 USB
  7. 通信),并且可以使⽤ LPD 等较旧的⽹络协议。
  8. CUPS 提供了⼀组命令⾏⼯具和⼀个 web 界⾯,⽤于管理 CUPS 和提交打印作业。它还提供了⼀个守
  9. 护进程 (cupsd),⽤于管理每个已配置打印机的作业队列。打印机的每个队列都与 PostScript 打 印机描
  10. 述 (PPD) ⽂件关联,该⽂件描述了打印机功能以及 CUPS 应如何为作业做好在该打印机上打印的准备。
  11. 1> 在使用打印机之前,首先要发现并设置打印机
  12. [root@workstation ~]# lab printing-automation start
  13. 模拟打印机
  14. [root@servera ~]# yum install -y avahi cups-ipptool
  15. [root@servera ~]# firewall-cmd --permanent --add-service=mdns
  16. success
  17. [root@servera ~]# firewall-cmd --reload
  18. [root@servera ~]# ippfind -T 30 发现打印机
  19. ipp://serverc.local:631/printers/rht-printer
  20. serverc.local:发现打印机的时候,这个名称client是访问不到的
  21. [root@serverc ~]# dig @224.0.0.251 -p 5353 serverc.local#没办法跑到打印机上执行这个命令。
  22. 找到地址:172.25.250.12
  23. 在client反解:[root@servera ~]# dig -x 172.25.250.12
  24. ipp://serverc.local:631/printers/rht-printer替换
  25. ipp://serverc.lab.example.com:631/printers/rht-printer
  26. 2> 设置打印队列
  27. [root@servera ~]# yum install -y cups
  28. Last metadata expiration check: 0:50:17 ago on Sun 04 Sep 2022 06:39:46 PM CST.
  29. Package cups-1:2.2.6-28.el8.x86_64 is already installed.
  30. Dependencies resolved.
  31. Nothing to do.
  32. Complete!
  33. [root@servera ~]# systemctl enable --now cups
  34. [root@servera ~]# lpadmin -p kevin -v ipp://serverc.lab.example.com:631/printers/rht-printer -m everywhere -E
  35. -p: 队列的名字
  36. -v: 打印机的URI
  37. -m: 使用everywhere 这个模块
  38. -E: 可立即启动打印机
  39. [root@servera ~]# lpstat -v查看
  40. device for kevin: ipp://serverc.lab.example.com:631/printers/rht-printer
  41. [root@servera ~]#
  42. -x 删除
  43. [root@servera ~]# lpadmin -d kevin -d 设置默认的队列
  44. 3> 管理作业
  45. [root@servera ~]# lp /root/anaconda-ks.cfg 默认的队列打印文件
  46. [root@servera ~]# lp -d kevin /etc/fstab 通过-d指定打印队列
  47. request id is kevin-8 (1 file(s))
  48. [root@servera ~]# cancel kevin-8
  49. 4>队列管理
  50. [root@servera ~]# cupsdisable -r "No paper" kevin 暂停,你把作业放到已经暂停打印队列中,他是不会打印的
  51. [root@servera ~]# cupsenable kevin
  52. [root@servera ~]# cupsreject -r "No Papare" kevin
  53. [root@servera ~]# lp /etc/fstab
  54. lp: Destination "kevin" is not accepting jobs.
  55. [root@servera ~]#
  56. [root@servera ~]# cupsaccept kevin
  57. ansible来管理打印机:问题在于:所有的操作都需要用到command模块来完成:
  58. 1> 通过ansible来实现的话打印机的URI是事先知道的。
  59. [student@workstation printing-auto]$ cat playbook.yml
  60. ---
  61. - name: config prineter
  62. hosts: clients
  63. become: true
  64. tasks:
  65. - name: install
  66. yum:
  67. name:
  68. - cups-ipptool
  69. - cups
  70. - avahi
  71. state: present
  72. - name: start service
  73. service:
  74. name: "{{ item }}"
  75. state: started
  76. enabled: yes
  77. loop:
  78. - cups
  79. - avahi-daemon
  80. - name: firewrmd
  81. firewalld:
  82. service: mdns
  83. permanent: yes
  84. state: enabled
  85. immediate: yes
  86. - name: find printer URi
  87. command: ippfind -T 3
  88. register: p_uri
  89. - name: set que
  90. command: lpadmin -p "kevin-{{ index }}" -v "{{ item }}" -m everywhere -E
  91. loop: "{{ p_uri['stdout_lines'] | replace('.local','') }}"
  92. loop_control:
  93. index_var: index
  94. - name: check default que is exit
  95. command: lpstat -d
  96. register: p_default
  97. - name: set default que
  98. command: lpadmin -d kevin-0
  99. when: "'kevin-0' not in p_default['stdout']"
  100. [student@workstation printing-auto]$ cat printer-accept.yml
  101. ---
  102. - name: Configure a print queue to accept jobs
  103. hosts: clients
  104. gather_facts: no
  105. become: yes
  106. tasks:
  107. - name: Confirm the print queue exists
  108. command: lpstat -p kevin-0
  109. register: cmdout
  110. ignore_errors: true
  111. changed_when: false
  112. - name: Tune the print queue to accept jobs
  113. command: cupsenable kevin-0
  114. when: cmdout.rc == 0

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/628365
推荐阅读
相关标签
  

闽ICP备14008679号