Set MTU on Guest

re-host.eu

New Member
Oct 3, 2017
29
1
1
30
Hey :)

is it possible to somehow achieve that the Guest uses a MTU of 1400? For example by forcing the e1000 or virtio network device to use a mtu of 1400?

Greetings,

Alex
 
So i Need to do this inside the vm? My Problem is, that i Need to set the mtu to 1400 to get internet Access. However i Cent set the mtu during linux Installation....
 
ok, so there is no way to "manipulate" the guest nic (virtio or emulated) to tell the guest that the maximum possible is a mtu of 1400?
 
  • Like
Reactions: DerDanilo
you can try to hack

/usr/share/perl5/PVE/QemuServer.pm

sub print_netdevice_full {
...
$tmpstr .= ",bootindex=$net->{bootindex}" if $net->{bootindex} ;
$tmpstr .= ",host_mtu=1400" if $net->{model} eq 'virtio';

then

systemctl restart pvedaemon


and start your vm.
 
  • Like
Reactions: re-host.eu
I would also prefer to implement this option in Proxmox. It worked great with your modification and the Vlans from Hetzner.
 
  • Like
Reactions: re-host.eu
Hello there, can anyone help to add this patch to PVE to configure MTU by Network Edit dialog
There is only to patches

First adds ability to specify in network config parameter ,mtu=MTU_NUM /etc/pve/qemu-server/VMID.conf

Code:
--- /usr/share/perl5/PVE/QemuServer.pm.orig     2018-08-30 03:07:40.885517605 +0300
+++ /usr/share/perl5/PVE/QemuServer.pm  2018-08-30 02:56:40.191065007 +0300
@@ -715,6 +715,12 @@
        description => "Rate limit in mbps (megabytes per second) as floating point number.",
        optional => 1,
     },
+    mtu => {
+       type => 'number',
+       minimum => 1200, maximum=> 9000,
+       description => "MTU",
+       optional => 1,
+    },
     tag => {
        type => 'integer',
        minimum => 1, maximum => 4094,
@@ -1839,6 +1845,7 @@
        $tmpstr .= ",vectors=$vectors,mq=on";
     }
     $tmpstr .= ",bootindex=$net->{bootindex}" if $net->{bootindex} ;
+    $tmpstr .= ",host_mtu=$net->{mtu}" if $net->{mtu} ;

     if ($use_old_bios_files) {
        my $romfile;
@@ -4634,7 +4641,7 @@
                &$safe_string_ne($oldnet->{trunks}, $newnet->{trunks}) ||
                &$safe_num_ne($oldnet->{firewall}, $newnet->{firewall})) {
                PVE::Network::tap_unplug($iface);
-               PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+               PVE::Network::tap_plug($iface, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate}, $newnet->{mtu});
            } elsif (&$safe_num_ne($oldnet->{rate}, $newnet->{rate})) {
                # Rate can be applied on its own but any change above needs to
                # include the rate in tap_plug since OVS resets everything.


Second patch is for GUI to edit MTU settings

Code:
--- /usr/share/pve-manager/js/pvemanagerlib.js.orig     2018-08-30 03:08:07.430582086 +0300
+++ /usr/share/pve-manager/js/pvemanagerlib.js  2018-08-30 02:37:28.504841119 +0300
@@ -1517,6 +1517,8 @@
                res.bridge = match_res[1];
            } else if ((match_res = p.match(/^rate=(\d+(\.\d+)?)$/)) !== null) {
                res.rate = match_res[1];
+           } else if ((match_res = p.match(/^mtu=(\d+)$/)) !== null) {
+               res.mtu = match_res[1];
            } else if ((match_res = p.match(/^tag=(\d+(\.\d+)?)$/)) !== null) {
                res.tag = match_res[1];
            } else if ((match_res = p.match(/^firewall=(\d+)$/)) !== null) {
@@ -1558,6 +1560,9 @@
        if (net.rate) {
            netstr += ",rate=" + net.rate;
        }
+       if (net.mtu) {
+           netstr += ",mtu=" + net.mtu;
+       }
        if (net.queues) {
            netstr += ",queues=" + net.queues;
        }
@@ -1785,7 +1790,7 @@
            if (!p || p.match(/^\s*$/)) {
                return; // continue
            }
-           var match_res = p.match(/^(bridge|hwaddr|mtu|name|ip|ip6|gw|gw6|firewall|tag|rate)=(\S+)$/);
+           var match_res = p.match(/^(bridge|hwaddr|mtu|name|ip|ip6|gw|gw6|firewall|tag|mtu|rate)=(\S+)$/);
            if (!match_res) {
                // todo: simply ignore errors ?
                return; // continue
@@ -18401,6 +18406,12 @@
            delete me.network.rate;
        }

+       if (values.mtu) {
+           me.network.mtu = values.mtu;
+       } else {
+           delete me.network.mtu;
+       }
+
        var params = {};

        params[me.confid] = PVE.Parser.printQemuNetwork(me.network);
@@ -18466,6 +18477,16 @@
                xtype: 'proxmoxcheckbox',
                fieldLabel: gettext('Disconnect'),
                name: 'disconnect'
+           },
+           {
+               xtype: 'numberfield',
+               fieldLabel: gettext('MTU'),
+               minValue: 1200,
+               maxValue: 9000,
+               value: '',
+               emptyText: '1500',
+               name: 'mtu',
+                allowBlank: true
            }
        ];

@@ -18484,6 +18505,7 @@
                            'firewall',
                            'model',
                            'macaddr',
+                            'mtu',
                            'rate',
                            'queues'
                        ];



After that you should restart pvedaemon and pveproxy
 

Attachments

  • qemu_server_pm.patch.txt
    1.3 KB · Views: 14
  • pvemanagerlib_js.patch.txt
    1.8 KB · Views: 6
  • Like
Reactions: re-host.eu
@Tacid

I'll do some changes if it's ok for you:

min-max mtu : 576-65535
only do it for virtio-net (not supported for other model card)
hotplug not working, add a check for this
remove the mtu param in tap_plug (it's doing nothing and not related to tap)
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!