Set MTU on Guest

Discussion in 'Proxmox VE: Networking and Firewall' started by re-host.eu, Jul 3, 2018.

  1. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
    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
     
  2. dietmar

    dietmar Proxmox Staff Member
    Staff Member

    Joined:
    Apr 28, 2005
    Messages:
    16,168
    Likes Received:
    268
    That is a guest setting (you set that inside the guest network stack).
     
  3. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
    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....
     
  4. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,113
    Likes Received:
    99
    you can try to force mtu 1400 on vmbr, but I think you'll have fragmentation if your guest use 1500 at install.
     
  5. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
    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?
     
  6. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,113
    Likes Received:
    99
    re-host.eu likes this.
  7. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
  8. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,113
    Likes Received:
    99
    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.
     
    re-host.eu likes this.
  9. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
    I will try out
     
  10. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
    @dietmar would it be possible to implement "the hack" in to the official release?
     
  11. aderumier

    aderumier Member

    Joined:
    May 14, 2013
    Messages:
    203
    Likes Received:
    18
    does it work for you ? (I don't have tested it)
     
  12. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
    Yes, for me it is working
     
  13. re-host.eu

    re-host.eu New Member

    Joined:
    Oct 3, 2017
    Messages:
    29
    Likes Received:
    0
  14. bfal

    bfal New Member

    Joined:
    Sep 28, 2009
    Messages:
    8
    Likes Received:
    1
    I would also prefer to implement this option in Proxmox. It worked great with your modification and the Vlans from Hetzner.
     
    re-host.eu likes this.
  15. Tacid

    Tacid New Member

    Joined:
    Aug 30, 2018
    Messages:
    1
    Likes Received:
    1
    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
     

    Attached Files:

    re-host.eu likes this.
  16. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,113
    Likes Received:
    99
    @Tacid

    I'll send patches based on this.
    Do you known if the value can be changed online ? (hotplug)
     
    re-host.eu likes this.
  17. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,113
    Likes Received:
    99
    @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)
     
  18. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,113
    Likes Received:
    99
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice