Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux 程式設計 >> Perl 程式設計

Net::SSH::Perl 報 Corrupted MAC on input 的排查與處理

錯誤現場

[Thu May 5 11:02:27 2016] [error] Corrupted MAC on input
 at /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/Net/SSH/Perl/Packet.pm line 229.

使用 Net::SSH::Perl 模組時偶爾會跳出這條錯誤。MAC(Message Authentication Code)校驗失敗,代表收到的封包內容與預期不符,通常指向底層網路或校驗和卸載出了問題,而不是 Perl 程式本身的邏輯錯誤。

處理方式一:關閉網卡卸載

某些網卡晶片在硬體層做 TCP/UDP 校驗和與 scatter-gather 卸載時,會與 SSH 加密流量互衝,導致封包被改動。關掉這些 offload 功能後即可恢復:

[root@dr-mysql01 ~]# ethtool -K eth0 tx off rx off
Actual changes:
rx-checksumming: off
tx-checksumming: off
scatter-gather: off

確認目前設定:

[root@dr-mysql01 ~]# ethtool -k eth0
Features for eth0:
rx-checksumming: off
tx-checksumming: off
scatter-gather: off
tcp-segmentation-offload: off
udp-fragmentation-offload: off
generic-segmentation-offload: on
generic-receive-offload: off
large-receive-offload: on
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off
receive-hashing: on

處理方式二:檢查防火牆

若關閉卸載後仍然間歇性失敗,下一步檢查防火牆規則。某些不完整的狀態追蹤或過於激進的封包檢查規則,會造成 SSH 長連線中的封包被攔截或重寫,同樣會引發 MAC 校驗失敗。

小結

這類錯誤的特性是「偶爾發生」,因此排查時要有耐心:先排除網卡卸載,再排除防火牆,最後才考慮改用 Net::OpenSSH 等以系統 ssh 用戶端為後端的替代方案。

Copyright © Linux教程網 All Rights Reserved